1. 程式人生 > >騰訊雲CentOS7安裝mysql各種報錯解決辦法!!以及Navicat連線(服務啟動不了解決辦法)

騰訊雲CentOS7安裝mysql各種報錯解決辦法!!以及Navicat連線(服務啟動不了解決辦法)

先釋放一下!氣死我了!!
背景:

在雲主機上安裝mysql來來回回重灌了十幾遍,氣得我昨晚還把雲主機的系統重灌了一遍!!!但是並沒有解決根本問題。最終還是今天上午解決了!

我安裝的mysql是5.6
首先說一下我的錯誤步驟!記住一下是錯誤步驟!

1、我是直接通過xshell的檔案傳輸將mysql的rpm包上傳到我的雲伺服器上的。
2.就是因為這一步背一篇部落格中的文章誤解,導致我安裝一天都沒安裝上去!就是安裝mysql之前,要先解除安裝MariaDB。
但是我用的命令是 # rpm -qa|grep MariaDB就找到一個安裝包。但是好像是我沒有搜清楚還是單詞中有大寫字母。今天使用另一個命令,才把mariadb的殘留解除安裝完。
#rpm -qa|grep -i mariadb

後面就是各種錯誤,然後就是卸了重灌,卸了重灌,卸了重灌。。。。。

================================================================================================

================================================================================================

終於我找到了解決方案了。

1.直接開始安裝:

#rpm -ivh MySQL-server-5.6.34-1.linux_glibc2.5.x86_64.rpm


然後出現下面的錯誤,各種file。。。。。。。

這個是因為CentOS 7的預設資料庫已經不再是MySQL了,而是MariaDB. MySQL安裝時的mysql lib庫與mariadb的庫、包衝突了,如下詳情所示(省略了大量日誌)
[[email protected] tmp]# rpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm 
Preparing... ################################# [100%]
file /usr/share/mysql/czech/errmsg.sys from
install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/danish/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/dutch/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/english/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/estonian/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/french/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/german/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/greek/errmsg.sys from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 ........................................................................................................................................................................ file /usr/share/mysql/charsets/macroman.xml from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64 file /usr/share/mysql/charsets/swe7.xml from install of MySQL-server-advanced-5.6.20-1.rhel5.x86_64 conflicts with file from package mariadb-libs-1:5.5.50-1.el7_2.x86_64

2.把mariadb的資料庫和依賴都解除安裝完
把剛才安裝失敗的mysql先解除安裝掉再重新安裝
解除安裝命令:#rpm -e MySQL-server-5.6.34-1.linux_glibc2.5.x86_64.rpm

3.再次安裝mysql
出現下面的錯誤:

FATAL ERROR: please install the following Perl modules before executing /usr/bin/mysql_install_db:

解除安裝MySQL相關元件後,重新安裝MySQL,發現缺少Perl相關模組。

使用yum安裝了 perl perl-devel相關包(注意:此處安裝MySQL時,沒有輸出安裝相關Detail的資訊,是因為Perl相關模組沒有安裝的緣故,此處還漏掉了安裝perl-Data-Dumper)

[root@azrlnx06 jirasetup]# yum install -y perl perl-devel

安裝完Perl相關元件後,重新安裝MySQL,如下所示,安裝成功,但是沒有輸出安裝相關Detail的資訊(因為沒有安裝perl-Data-Dumper),啟動MySQL報錯

root@azrlnx06 jirasetup]# rpm -ivh MySQL-server-advanced-5.6.20-1.rhel5.x86_64.rpm 
Preparing... ################################# [100%]
Updating / installing...
1:MySQL-server-advanced-5.6.20-1.rh################################# [100%]
[root@azrlnx06 jirasetup]# rpm -ivh MySQL-client-advanced-5.6.20-1.rhel5.x86_64.rpm 
Preparing... ################################# [100%]
Updating / installing...
1:MySQL-client-advanced-5.6.20-1.rh################################# [100%]
[root@azrlnx06 ~]# service mysql start
Starting MySQL............. ERROR! The server quit without updating PID file (/var/lib/mysql/azrlnx06.pid).
[root@azrlnx06 ~]#

找到MySQL的錯誤日誌,然後檢查/var/lib/mysql/azrlnx06.err錯誤日誌,發現如下錯誤資訊

查詢錯誤日誌的方法是,先查詢err檔案,再去檢視錯誤內容:

[[email protected] mysql]# find / -name *.err
/var/lib/mysql/azrlnx06.err
/var/log/azure/Microsoft.OSTCExtensions.LinuxDiagnostic/2.3.9011/mdsd.err
/var/log/azure/Microsoft.OSTCExtensions.LinuxDiagnostic/2.3.9013/mdsd.err
/var/log/mdsd/mdsd.err
[[email protected] mysql]# more /var/lib/mysql/azrlnx06.err
161111 03:28:25 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2016-11-11 03:28:25 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-11-11 03:28:25 2144 [Note] Plugin 'FEDERATED' is disabled.
/usr/sbin/mysqld: Table 'mysql.plugin' doesn't exist
2016-11-11 03:28:25 2144 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2016-11-11 03:28:25 2144 [Note] InnoDB: Using atomics to ref count buffer pool pages
2016-11-11 03:28:25 2144 [Note] InnoDB: The InnoDB memory heap is disabled
2016-11-11 03:28:25 2144 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2016-11-11 03:28:25 2144 [Note] InnoDB: Memory barrier is not used
2016-11-11 03:28:25 2144 [Note] InnoDB: Compressed tables use zlib 1.2.3
2016-11-11 03:28:25 2144 [Note] InnoDB: Using Linux native AIO
2016-11-11 03:28:25 2144 [Note] InnoDB: Using CPU crc32 instructions
2016-11-11 03:28:25 2144 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2016-11-11 03:28:25 2144 [Note] InnoDB: Completed initialization of buffer pool
2016-11-11 03:28:25 2144 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2016-11-11 03:28:25 2144 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2016-11-11 03:28:25 2144 [Note] InnoDB: Database physically writes the file full: wait...
2016-11-11 03:28:26 2144 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2016-11-11 03:28:31 2144 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2016-11-11 03:28:37 2144 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2016-11-11 03:28:37 2144 [Warning] InnoDB: New log files created, LSN=45781
2016-11-11 03:28:37 2144 [Note] InnoDB: Doublewrite buffer not found: creating new
2016-11-11 03:28:37 2144 [Note] InnoDB: Doublewrite buffer created
2016-11-11 03:28:37 2144 [Note] InnoDB: 128 rollback segment(s) are active.
2016-11-11 03:28:37 2144 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-11-11 03:28:37 2144 [Note] InnoDB: Foreign key constraint system tables created
2016-11-11 03:28:37 2144 [Note] InnoDB: Creating tablespace and datafile system tables.
2016-11-11 03:28:38 2144 [Note] InnoDB: Tablespace and datafile system tables created.
2016-11-11 03:28:38 2144 [Note] InnoDB: Waiting for purge to start
2016-11-11 03:28:38 2144 [Note] InnoDB: 5.6.20 started; log sequence number 0
2016-11-11 03:28:38 2144 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: ef3b0cd5-a7be-11e6-98b3-000d3a8062fe.
2016-11-11 03:28:38 2144 [Note] RSA private key file not found: /var/lib/mysql//private_key.pem. Some authentication plugins will not work.
2016-11-11 03:28:38 2144 [Note] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2016-11-11 03:28:38 2144 [Note] Server hostname (bind-address): '*'; port: 3306
2016-11-11 03:28:38 2144 [Note] IPv6 is available.
2016-11-11 03:28:38 2144 [Note] - '::' resolves to '::';
2016-11-11 03:28:38 2144 [Note] Server socket created on IP: '::'.
2016-11-11 03:28:38 2144 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
161111 03:28:38 mysqld_safe mysqld from pid file /var/lib/mysql/azrlnx06.pid ended
clip_image002

索了一些相關資料,應該是perl-Data-Dumper模組沒有安裝,導致安裝過程中,初始化資料庫失敗,所以啟動MySQL服務時,找不到相關係統表。具體參考官方文件MySQL-server RPM does not install perl-Data-Dumper as a dependency

**Description:
MySQL-server requires perl-Data-Dumper to function. However, perl-Data-Dumper is not listed by the MySQL-server RPM as a dependency. So if a linux server does not have perl-Data-Dumper installed, the install-mysql-db will fail. And because of missing the initial database, the mysql service could not be started.
How to repeat:
On a linux server, make sure there is no perl-Data-Dumper installed. Install MySQL-server using yum. There should be error message complaining database could not be created.
Suggested fix:
Add perl-Data-Dumper as a dependency of the RPM package**

解決方法:

1:安裝perl-Data-Dumper模組。

[root@azrlnx06 mysql]# yum install -y perl-Data-Dumper

2:初始化資料庫

[[email protected] mysql]# sudo mysql_install_db --user=mysql --basedir=/usr/ --ldata=/var/lib/mysql/
clip_image003 

這裡寫圖片描述

最後啟動mysql服務的時候就可以了。

[[email protected] mysql]# service mysql start
Starting MySQL. SUCCESS! 
[[email protected] mysql]# /usr//bin/mysqladmin -u root password 'Qwe!23'
Warning: Using a password on the command line interface can be insecure.

================================================================================================

================================================================================================
下面來說一下怎麼用Navicat連線這個騰訊雲的mysql伺服器

1.要開放3306埠

firewall-cmd --zone=public --add-port=3306/tcp --permanent
我的系統是CentOS7所以命令和以前的好像不一樣,好多百度上的命令用不了

2.用Navicat連線的時候報錯,是因為沒有對使用者授權

示例:
Sql程式碼

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; (如果要限定某一個ip只要把%改為ip地址就可以了)

執行完後,再
mysql:flush privileges;
重新整理一下許可權就可以了,不用重啟

至此,mysql安裝好了,Navicat也連線上了遠端mysql了。

================================================================================================
由於mysql上次安裝的問題百出,,導致我的專案跑起來的時候,mysql老是自動關閉,所以,我重灌了系統,重新安裝mysql。
並更新部落格!
按照下面第三條部落格的方法就可以了!希望能幫助大家