centos7.6 安装Mysql5.7

添加MySQL Yum库

# wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
# rpm -ivh mysql80-community-release-el7-1.noarch.rpm

选择要安装的MySQL版本

# vim /etc/yum.repos.d/mysql-community.repo
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=0  // 将这里的0改为1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=1  //将这里的1改为0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

enabled=0为禁用对应版本的YUM库,enabled=1为启用,默认8.0的配置为enabled=1,安装5.7的话,就把8.0的enabled=1修改为enabled=0,然后把5.7的enabled=0修改为enabled=1,修改完成,:wq保存

安装MySQL并启动

# yum install mysql-community-server
# service mysqld start

查看MySQL初始密码

# sudo grep 'temporary password' /var/log/mysqld.log

如果查询为空则无密码,直接回车即可

修改MySQL初始密码

# mysql -u root -p
> ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

给root 权限开启 远程登录

> use mysql;
> select user,host from user;
> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

为数据库创建单独的用户并给他单独数据库的所有权限

> create user 'test'@'%' identified by 'CKNiNXZgLk4H2kqYS';
> grant all privileges ON test.* TO 'test'@'%';
> ALTER USER 'test'@'%' IDENTIFIED WITH mysql_native_password BY 'CKNiNXZgLk4H2kqYS';

ERROR

ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 45, found 42. Created with MySQL 50564, now running 50729. Please use mysql_upgrade to fix this error.

# mysql_upgrade -u root -p
# mysql -uroot -p

密码为空直接回车

[Err] 1682 - Native table ‘performance_schema’.‘session_status’ has the wron

# mysql_upgrade -u root -p
> set @@global.show_compatibility_56=ON;

注:从mysql5.7.6开始information_schema.global_status已经开始被舍弃,为了兼容性,此时需要打开 show_compatibility_56

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章