centos 安裝 mysql

首先使用rpm下載mysql依賴。在這裏我裝的是mysql57版本。

 sudo rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

很有可能出現下面的錯誤:

Error: mysql80-community-release conflicts with mysql57-community-release-el7-11.noarch

這個表示出現了兩個版本衝突的問題。因此需要刪除mysql80相關依賴。

rpm -e --nodeps mysql80-community-release-el7-2.noarch

用下面指令查看當前mysql依賴包的版本是否一致:

[root@localhost downloads]# sudo yum repolist all | grep mysql | grep enabled
!mysql-connectors-community/x86_64 MySQL Connectors Community    enabled:    131
!mysql-tools-community/x86_64      MySQL Tools Community         enabled:    100
!mysql57-community/x86_64          MySQL 5.7 Community Server    enabled:    384

然後執行一下指令:

sudo yum -y install mysql-community-server
sudo systemctl start mysqld
sudo systemctl status mysqld

如果執行上面最後一個指令顯示的狀態是running則表示成功。下一步更改mysql的編碼格式爲utf8。在/etc/my.cnf文件中添加:

[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

接下來使用下面指令修改密碼:

sudo systemctl stop mysqld
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
sudo systemctl start mysqld
mysql -u root
    #進入mysql界面之後執行下面三個指令修改密碼:
    1.UPDATE mysql.user SET authentication_string = PASSWORD('123456')  WHERE User = 'root' AND Host = 'localhost';
    2.FLUSH PRIVILEGES;
    3.quit
systemctl stop mysqld
systemctl unset-environment MYSQLD_OPTS
systemctl start mysqld
mysql -u root -p

輸入剛纔修改的密碼之後就可以登錄成功了。

發佈了80 篇原創文章 · 獲贊 133 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章