Centos7 上安裝mysql趕上的問題:mysql沒法正常啓動

第一次在Centos上安裝mysql遇到的一些問題。javascript

第一步就遇到問題,安裝mysql-server報錯沒有可用包。java

 
【解決方法】 
先要安裝mysqlmysql

# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community-release-el7-5.noarch.rpm
  • 1
  • 2

以後再安裝mysql-serverlinux

# yum -y install mysql-server
  • 1

而後systemctl enable mysqld設置mysql自啓動 以後systemctl start mysqld這時候出問題了,運行以後一直卡着沒有反應,以下sql

[root@localhost ~]# systemctl start mysqld Redirecting to /bin/systemctl start mysql.service
  • 1
  • 2

systemctl status mysqld查看mysql服務的狀態以下數據庫

[root@localhost sbin]# systemctl status mysqld
● mysqld.service - MySQL Community Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: activating (start-post) since 一 2017-05-15 17:04:12 CST; 5min ago Process: 981 ExecStart=/usr/bin/mysqld_safe --basedir=/usr (code=exited, status=0/SUCCESS) Process: 938 ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=0/SUCCESS) Main PID: 981 (code=exited, status=0/SUCCESS); : 982 (mysql-systemd-s) CGroup: /system.slice/mysqld.service └─control ├─ 982 /bin/bash /usr/bin/mysql-systemd-start post └─2315 sleep 1 5月 15 17:04:12 localhost.localdomain systemd[1]: Starting MySQL Community Server... 5月 15 17:04:15 localhost.localdomain mysqld_safe[981]: 170515 17:04:15 mysqld_safe Logging to '/var/lo...g'. 5月 15 17:04:15 localhost.localdomain mysqld_safe[981]: 170515 17:04:15 mysqld_safe Starting mysqld dae...sql Hint: Some lines were ellipsized, use -l to show in full.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

看不出問題,查看mysql的日誌終於找到問題vim /var/log/mysqld.logvim

2017-05-14 16:40:16 0 [Note] Binlog end 170514 16:40:16 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended 170515 17:04:15 mysqld_safe Logging to '/var/log/mysqld.log'. 170515 17:04:15 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql 2017-05-15 17:04:18 0 [ERROR] /usr/sbin/mysqld: ambiguous option '--character-set=utf8' (character-set-client-handshake, character_sets_dir) 2017-05-15 17:04:18 0 [ERROR] Aborting
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

原來是my.cnf文件中設置默認字符編碼我寫成character-set=ut8而centos7版本中應該設置爲default-character-set=utf8centos

以後繼續啓動mysql仍然沒法啓動,查看日誌以下安全

2017-05-15 17:14:21 1195 [Warning] Buffered warning: Changed limits: table_open_cache: 431 (requested 2000) 2017-05-15 17:14:21 1195 [Note] Plugin 'FEDERATED' is disabled. /usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist 2017-05-15 17:14:21 1195 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it. 2017-05-15 17:14:21 1195 [Note] InnoDB: Using atomics to ref count buffer pool pages 2017-05-15 17:14:21 1195 [Note] InnoDB: The InnoDB memory heap is disabled 2017-05-15 17:14:21 1195 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins 2017-05-15 17:14:21 1195 [Note] InnoDB: Memory barrier is not used 2017-05-15 17:14:21 1195 [Note] InnoDB: Compressed tables use zlib 1.2.3 2017-05-15 17:14:21 1195 [Note] InnoDB: Using Linux native AIO 2017-05-15 17:14:21 1195 [Note] InnoDB: Not using CPU crc32 instructions 2017-05-15 17:14:21 1195 [Note] InnoDB: Initializing buffer pool, size = 128.0M 170515 17:04:18 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

注意ERROR 
Can’t open the mysql.plugin table. Please run mysql_upgrade to create it. 
【解決方法】 
在運行初始化權限表的時候使用增長參數–datadir 
mysql_install_db –user=mysql –datadir=/usr/local/mysql/var 
百度後bash

安裝完mysql server時,通常要執行這個腳本對數據庫初始化。 運行這個腳本,會初始化mysql的data目錄,而且建立那些系統表。 
一樣也會初始化系統表空間而且關聯innodb表與數據結構。 
更多的相關能夠點擊這裏查看

以後啓動服務依然卡住,回看前面執行命令以後的提示

Alternatively you can run:
  /usr/bin/mysql_secure_installation
  • 1
  • 2

即執行MySQL安全配置嚮導mysql_secure_installation 
安裝完mysql-server 會提示能夠運行mysql_secure_installation。運行mysql_secure_installation會執行幾個設置: 
a)爲root用戶設置密碼 
b)刪除匿名帳號 
c)取消root用戶遠程登陸 
d)刪除test庫和對test庫的訪問權限 
e)刷新受權表使修改生效 
執行以後systemctl restart mysqld命令能夠正常執行了

能夠正常啓動登陸mysql

相關文章
相關標籤/搜索