Bootstrap

虚拟机安装mysql

·查看系统的数据库:

rpm -qa|grep mariadb

卸载虚拟机自带数据库: rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64

安装 yum install -y perl net-tools

安装 yum install -y wget

1.下载:

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64

或者直接在虚拟机上传下载好的压缩包

2.解压: tar -zxvf mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz

移动到usr下的local并命名为mysql: mv mysql-5.7.40-linux-glibc2.12-x86_64 /usr/local/mysql ···在mysql中新建目录data存放数据

[root@localhost /]# mkdir /usr/local/mysql/data 

3.配置环境变量

[root@localhost /]# vi /etc/profile

进入后按shift+g键 按下i键 滑到最后进行·插入

export PATH=/usr/local/mysql/bin:$PATH

再点击esc键退出编辑模式 :wq退出

重载/etc/profile 文件:[root@localhost ~]# source /etc/profile

查看PATH值验证配置是否成功 [root@localhost ~]# echo $PATH

4.修改配置

找到my.cnf文件

[root@localhost ~]# mysql --help | grep 'my.cnf'

order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/my.cnf /etc/mysql/my.cnf /usr/local/mysql/etc/my.cnf ~/.my.cnf

进入文件[root@localhost ~]# vi /etc/my.cnf 按i键

[mysqld]

# 设置mysql根目录

basedir=/usr/local/mysql

# 设置数据库存放数据的目录

datadir=/usr/local/mysql/data

[mysqld safe]

log-error=/var/lib/mysql/localhost.err

pid-file=/var/lib/mysql/localhost.pid

5.用户与用户组

[root@localhost ~]# groupadd mysql

[root@localhost ~]# useradd -r -g mysql mysql

变更用户和用户组授权命令: [root@localhost ~]# chown -R mysql:mysql /usr/local/mysql

6.初始化:

mysqld --initialize --user=mysql

 临时密码Gpar;ih(+7lf

7.安装ssl [root@localhost ~]# mysql_ssl_rsa_setup --datadir=/usr/local/mysql/data

添加权限:[root@localhost ~]# chmod -R a+r /usr/local/mysql/data/server-key.pem

8.配置

 8-1.开机启动

a.复制启动脚本到资源目录

[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld

b. mysqld文件添加执行权限

[root@localhost ~]# chmod +x /etc/rc.d/init.d/mysqld

c.mysqld服务添加至系统服务

[root@localhost ~]# chkconfig --add mysqld

d.查询mysqld服务:

[root@localhost ~]# chkconfig --list mysqld mysqld

0:关 1:关 2:开 3:开 4:开 5:开 6:关 说明已打开

e.启动mysqld服务

[root@localhost ~]# service mysqld start

Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.

SUCCESS! 

9.修改密码

[root@localhost ~]# mysql -uroot -p

Enter password: 临时密码

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 2

Server version: 5.7.40

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its affiliates.

Other names may be trademarks of their respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> alter user 'root'@'localhost' identified by '123456'; // 修改为123456

Query OK, 0 rows affected (0.00 sec)

mysql> quit 

Bye

;