1. 程式人生 > >centos安裝mysql流程以及解決啟動失敗問題

centos安裝mysql流程以及解決啟動失敗問題

ystemd .rpm reat disable test 進行 node ins 我們

安裝步驟

安裝前,我們可以檢測系統是否自帶安裝 MySQL:

rpm -qa | grep mysql

如果你系統有安裝,那可以選擇進行卸載:

rpm -e mysql  // 普通刪除模式
rpm -e --nodeps mysql 

安裝

    wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
    rpm -ivh mysql57-community-release-el7-9.noarch.rpm
    yum install mysql-server

初始化 MySQL:

mysqld --initialize

啟動 MySQL:

    systemctl start mysqld

查看 MySQL 運行狀態:

    systemctl status mysqld

centos啟動mysql報錯

$ systemctl status mysqld.service
● mysqld.service - MySQL Server
  Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
 Active: activating (start-pre) since 一 2018-09-03 06:27:17 EDT; 631ms ago
   Docs: man:mysqld(8)
         http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 26472 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=1/FAILURE)
Control: 26489 (mysqld_pre_syst)
 Memory: 26.6M
 CGroup: /system.slice/mysqld.service
       └─control
         ├─26489 /bin/bash /usr/bin/mysqld_pre_systemd
         └─26506 /usr/bin/python -Es /usr/sbin/semanage fcontext -a -e /var/lib/mysql /var/lib/mysql-files

9月 03 06:27:17 test241vm22 systemd[1]: Starting MySQL Server...

解決辦法

chown mysql:mysql -R /var/lib/mysql

修改初始密碼

     You must reset your password using ALTER USER statement before executing this statement.

安裝完mysql 之後,登陸以後,不管運行任何命令,總是提示這個

step 1: SET PASSWORD = PASSWORD(‘your new password‘);

step 2: ALTER USER ‘root‘@‘localhost‘ PASSWORD EXPIRE NEVER;

step 3: flush privileges;

創建用戶,授權遠程登陸

create user ‘test‘@‘10.1.3.200‘ identified by ‘123456‘;
grant all privileges on *.* to ‘sl_test‘@‘10.100.0.0‘;
    flush privileges;

導入數據庫

source /data/model/tables.sql       

centos安裝mysql流程以及解決啟動失敗問題