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

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