1.安装mysql
1.下载离线安装包:mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar
2.将部署包存放到/opt/文件夹下
3.解压并安装
cd /opt/
mkdir mysql
tar -xvf /opt/mysql-5.7.30-1.el7.x86_64.rpm-bundle.tar -C /opt/mysql
cd /opt/mysql/
rpm -Uvh *.rpm --nodeps --force
2. Mysql配置
1.首先关闭mysql服务:
service mysqld stop
2.然后修改配置文件:
vi /etc/my.cnf
3.接下来加入一句代码即可空密码登录mysql:
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-grant-tables
4.开启mysql服务:
service mysqld start
5.空密码登录mysql:
mysql -u root -p
#输入命令回车进入,出现输入密码提示直接回车
6.设置mysql密码:
mysql> set password for root@localhost = password('123456');
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>quit;
Bye
7.关闭无密码登陆配置:
关闭服务
service mysqld stop
打开配置:
vi /etc/my.cnf
注释无密码登陆功能
# Disabling symbolic-links is recommended to prevent assorted security risks
# skip-grant-tables # 注释掉这句话
8.启动新密码mysql服务
启动mysql
service mysqld start # 启动mysql服务
新密码登陆:
mysql -uroot -p
3.设置mysql开机自启
systemctl enable mysqld