Centos 7安装Mysql5.7

时间:2021-03-21 21:07:15

1.下载(国内镜像,比搜狐的快一点):http://mirrors.ustc.edu.cn/mysql-ftp/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz

2.依赖

yum install libaio

3.

groupadd mysql
useradd -r -g mysql -s /bin/false mysql
cd /usr/local
tar zxvf /path/to/mysql-VERSION-OS.tar.gz
ln -s full-path-to-mysql-VERSION-OS mysql
cd mysql
scripts/mysql_install_db --user=mysql
bin/mysqld_safe --user=mysql &
#回车cp support-files/mysql.server /etc/init.d/mysql.server

4. 加入skip-grant-tables(跳过权限)

vi /etc/my.cnf
[mysqld]
skip-grant-tables

5.启动服务

systemctl start mysql

6.

 mysql -u root -p

无密码,直接回车

7.修改密码

use mysql;
update mysql.user set authentication_string=password('123456') where User='root' and Host='localhost';

8.设置密码不过期,不然没法登陆

update user set password_expired='N' where user='root';
flush privileges;

9.退出后在,/etc/my.cnf中 将权限过滤的那条删除(注释)

#删除skip-grant-tables
#skip-grant-tables

10.重启mysql服务

systemctl restart mysql

11.登陆后启动远程访问

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;