1. 程式人生 > >原碼安裝MySQL時出現的問題和解決方法

原碼安裝MySQL時出現的問題和解決方法

原碼安裝MySQL時出現的問題和解決方法

 

1.配置檔案沒有修改

初始化資料庫資訊
mysqld --initialize --user=mysql
mysqld --initialize --user=mysql 初始化資料庫目錄
初始化成功會生成 data 目錄,屬主為 mysql,如果不不加 --user=mysql ,則資料庫目錄為 root 許可權, 會出錯
[[email protected] ~]# mysqld_safe & 開啟伺服器就會出現錯誤
[1] 1146

Logging to '/usr/local/mysql/data/wangying.err'.
2018-08-31T10:05:12.467041Z mysqld_safe Directory '/var/lib/mysql' for UNIX socket file don't exists.


用客戶端登入
[[email protected] ~]# mysql -uroot -p' bE:+/Mth#1<&'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[[email protected] ~]#

解決辦法:

修改配置檔案/etc/my.cnf
[mysqld]

#datadir=/var/lib/mysql
#沒有改yum預設的位置
#socket=/var/lib/mysql/mysql.sock


# Disabling symbolic-links is recommended to prevent assorted security risks

重新進行初始化

2..服務端沒有啟動

[[email protected] ~]# ps aux |grep mysql
root 11514 0.0 0.0 112704 964 pts/1 R+ 18:12 0:00 grep --color=auto mysql
[[email protected] ~]#
客戶端連線資料庫
[[email protected] ~]# mysql -uroot -p' bE:+/Mth#1<&'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
[

[email protected] ~]#

將/etc/my.cnf配置檔案修改正常,
但是服務端沒有開啟
注意:如果上面的資料庫的初始化的時候沒有修改配置檔案,此時要將上面初始化生成的data檔案刪除從新刪除,否則直接將配置檔案改完,又會出現下面的問題
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor
解決方法:重新初始化資料庫就可以了

3.將/tmp/下的套接字檔案刪除

如果配置檔案中沒有寫套接字的位置,會在/tmp下
[[email protected] mysql]# ls /tmp/
mysql.sock systemd-private-e5d34ffed9ad4a4594d57aa109d7cca4-chronyd.service-oyTPww
mysql.sock.lock vmware-root
[[email protected] mysql]# ls /tmp/mysql.sock
/tmp/mysql.sock
[[email protected] mysql]# ll /tmp/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Aug 31 19:01 /tmp/mysql.sock
[[email protected] mysql]# rm -rf /tmp/mysql.sock
[[email protected] mysql]#
客戶端連線MySQL服務
Shutting down MySQL. SUCCESS!
[[email protected] init.d]# ./mysqld start
Starting MySQL. SUCCESS!
[[email protected] init.d]# ./mysqld status
SUCCESS! MySQL running (11875)
[[email protected] init.d]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

[[email protected] init.d]#
這樣就需要將MySQL的伺服器重新啟動,資料庫就能正常使用
[[email protected] init.d]# ./mysqld stop
Shutting down MySQL.. SUCCESS!
[[email protected] init.d]# ./mysqld start
Starting MySQL. SUCCESS!
[[email protected] init.d]# ./mysqld status
SUCCESS! MySQL running (12026)
[[email protected] init.d]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22 Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
如果自己編譯的MySQL時,將配置檔案中的套接字檔案修改位置改變,會出現下面的問題,可以這樣解決
[[email protected] init.d]# mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
修改MySQL的socket檔案後,在後面/etc/my.cnf新增
[client]
socket=/var/lib/mysql/mysql.sock