centos7 搭建 mysql8

記錄centos搭建mysql遇到的坑mysql

1.  直接用centos 的yum命令進行安裝,發現找不到 mysql-server,因而下載 rpm文件進行後在進行安裝,具體可參考官網 https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/sql

2. mysql服務端安裝成功,並從本地啓動後,登錄不上。數據庫

    正常來講 mysql(8版本) 第一次 啓動後,會在  /var/log/mysqld.log  記錄一個 root 對應的臨時密碼  , 使用此密碼經過 mysql -uroot -p"臨時密碼" 可登錄到mysql。centos

 臨時密碼能夠經過 grep 'temporary password' /var/log/mysqld.log 這個命令查看到

    若是發現  /var/log/mysqld.log 文件爲空或者無密碼 。  能夠在 /etc/my.cnf 文件的第二行插入 skip-grant-tables ,文件內容大體以下:socket

[mysqld]
#skip-grant-tables    -- 這一行表示能夠不輸入密碼直接登入 mysql
#skip-networking      -- 這一行表示本機運行,外部沒法鏈接
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

default-character-set=utf8
View Code

   這時,你已經能夠登入mysql了,你還須要作的是 修改root密碼,並新建普通用戶,設置其可遠程登錄。ide

   首先,設置 root 密碼爲空  ALTER USER 'root'@'localhost' IDENTIFIED BY '';  或者 直接 update mysql.user set authentication_string = '' where user = 'root' and host = 'localhost';ui

   接着先將  /etc/my.cnf  文件中的  skip-grant-tables 註釋掉 , 並重啓服務  service restart mysqld ,  使用  mysql -uroot -p'' 登錄mysqlspa

  登錄mysql後你就能夠修改 root 用戶的密碼了,使用命令   ALTER USER 'root'@'localhost' IDENTIFIED BY 'pwd'; 設置密碼   [ 這裏千萬不要直接 update 設置密碼 ]   。.net

若是你不想設置複雜的密碼,可是它一直報你的密碼,你能夠:
SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password.check_user_name    | ON     |
| validate_password.dictionary_file    |        |
| validate_password.length             | 8      |
| validate_password.mixed_case_count   | 1      |
| validate_password.number_count       | 1      |
| validate_password.policy             | MEDIUM |
| validate_password.special_char_count | 1      |
+--------------------------------------+--------+
其中 validate_password.policy 常量表明的是密碼等級,0是low
       validate_password.length 常量表明的是密碼長度 
經過 set global validate_password_length=1; 來設置,
View Code

  密碼改完了, CREATE USER 'username'@'host' IDENTIFIED BY 'password';  新建一個用戶 ; rest

  修改數據庫外部可訪問: update mysql.user set host = '%' where user = 'user' and host = 'host';   

 用戶提權限: GRANT ALL ON *.* TO 'user'@'%';       最後須要對外開放mysql監聽的端口,通常爲 3306

 

 

 

 

 

 

 參考:

相關文章
相關標籤/搜索