centos 7 安裝 MYSQL 5.7

下載MySQL官方Yum Repository

在一個合適的地方把這個下下來

wget -i http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

安裝MySQL的Yum Repository

yum -y install mysql57-community-release-el7-7.noarch.rpm

安裝MySQL數據庫的服務器版本

yum -y install mysql-community-server

啓動數據庫

systemctl start  mysqld.service

可以用命令systemctl status mysqld.service查看MySQL數據庫啓動後的服務狀態。

獲取初始密碼

grep "password" /var/log/mysqld.log

會顯示這麼一句:

A temporary password is generated for root@localhost: su%lsu7Rx

這個亂七八糟的就是你的初始密碼了,雖然有了密碼,但是還是要修改密碼後才能真正用起來,不然就會報錯:


修改root用戶密碼

mysql -uroot -p
Enter password:                       ####輸入剛剛那一堆亂七八糟的東西
##……
##……

修改密碼:
方法一:

mysql> set password for 'root'@'localhost'=password('123');

方法二:

alter user 'root'@'localhost' identified by '123';

我這裏很懶,寫的123,但是如果你也這麼寫,那就可能會報錯:


仔細看一下初始密碼,發現它有:大寫、小寫、數字、特殊符號,長度在8位以上。那麼你也需要弄一個符合這些條件的密碼來。當然你也可以修改mysql的配置使得密碼的要求被降低,但是我覺得有規律的話,複雜一點也沒啥問題嘛。附上使用簡單密碼教程

安裝結束

修改完密碼後 使用exit退出mysql,然後再執行mysql -uroot -p時,用上的就是剛剛改好的密碼了。

[root@hlxfdymbz2 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

mysql> exit
Bye

這樣,mysql就全部弄好能用了。

其他

當我用Navicat 連剛剛弄好的數據庫時,發現一直連不上,原因和nginx裏注意部分出現的問題一樣,是安全組配置問題。因爲我新買的服務器的安全組入網配置沒有3306端口,而數據庫的端口大多默認爲3306(你也可以改咯?),所以連不上,去安全組配置以下,協議類型爲MySQL:

配置好後終於連上了,但是卻又報了個錯。

1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL server

原因無法給遠程連接的用戶權限。這時候我們修改下權限就好啦:
Sql代碼 :

GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION; 

之後再執行:

flush privileges; 

刷新下權限就OK了。
再通過Navicat 去連接,就可以連上數據庫了。

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