P1-Linux下安裝MySQL及登陸用戶配置

Linux下安裝MySQL及登陸用戶配置mysql

環境:Centos7.4    Mysql5.6sql

 

1. 查詢是否安裝 MySQL和MariaDBvim

  rpm -qa | grep -i mysqlrest

  rpm -qa | grep -i maria日誌

 

2. 卸載已有的 MySQL 和 MariaDBserver

  將1中查詢結果一一刪除rem

  yum remove mysql-community mysql-community-server mysql-community-libs mysql-community-commonget

  yum remove maria**   (不可用*,須改成確切名稱)it

 

3. 確認是否徹底卸載登錄

  rpm -qa | grep -i mysql

 

4. 下載yum源安裝(Centos7.4中已經不包含 MySQL 的源)

  wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

  rpm -ivh mysql-community-release-el7-5.noarch.rpm  

 

5. 安裝 MySQL

  yum install mysql-community-server

 

6. 修改配置文件

  vim /etc/mysqld

  在 [mysqld] 下添加以下行:

    character-set-server=utf8

    default-character-set=utf8

    修改此行(沒有則添加)

    datadir=/opt/data  #安裝時未指定,則缺省路徑爲/opt/data,默認的配置文件不是此路徑,會致使服務沒法啓動

 

7. 啓動MySQL

  systemctl restart mysqld.service

 

8. 查看運行狀態

  systemctl status mysqld.service

 

注:若是啓動失敗,能夠去 /var/log/mysqld.log 查看日誌,以確認錯誤緣由

 

9. 本機登陸

  mysql -u root -p    #首次登錄默認密碼爲空

  # 刪除全部用戶名爲空的帳戶

  delete from mysql.user where user = '';

  # 給 root 帳戶設置密碼

  set password from root@localhost = password("123456");

  set password from root@'127.0.0.1' = password("123456");

 

  # 建立新用戶並附權限

  GRANT ALL PRIVILEGES ON *.* TO 'user01'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;

  FLUSH PRIVILEGES;

相關文章
相關標籤/搜索