【服務器環境搭建】之 Centos安裝mysql教程

卸載原有mysql

檢查是否已經安裝Mysql

rpm -qa | grep mysql

卸載已經安裝的Mysql

## 刪除mysql相關目錄
find / -name mysql |xargs rm -rf

安裝新的mysql

安裝yum源

yum localinstall mysql57-community-release-el7-8.noarch.rpm

安裝mysql服務

yum install -y mysql-community-server

檢查mysql安裝結果

[root@baimaduhe src]# mysql -V
mysql  Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using  EditLine wrapper

啓動Mysql 服務

systemctl start mysqld

設置Mysql 開機啓動

systemctl start mysqld

獲取Mysql 初始密碼

[root@baimaduhe src]# grep 'temporary password' /var/log/mysqld.log
2020-01-17T15:12:08.755778Z 1 [Note] A temporary password is generated for root@localhost: ;QsQkdLBl6kR

連接到mysql

[root@baimaduhe src]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

配置mysql

將密碼強度設置爲低

學習用爲了方便才這樣設置,生產環境請勿這樣設置

 set global validate_password_policy=LOW;

修改mysql

mysql> ALTER USER USER() IDENTIFIED BY 'new_password';

允許遠程訪問

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

刷新配置

FLUSH PRIVILEGES;

遠程登錄mysql

mycli -u root -p<your_password> -h <service ip> -P 3306

參考資料

  • https://www.cnblogs.com/123hll/p/9633422.html
  • https://blog.csdn.net/muziljx/article/details/81541896
  • https://www.mysql.com/
發佈了17 篇原創文章 · 獲贊 4 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章