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

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

 

1.配置文件沒有修改

初始化數據庫信息
mysqld --initialize --user=mysql
mysqld --initialize --user=mysql 初始化數據庫目錄
初始化成功會生成 data 目錄,屬主爲 mysql,如果不不加 --user=mysql ,則數據庫目錄爲 root 權限, 會出錯
[root@wangying ~]# 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.

用客戶端登錄
[root@localhost ~]# 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)
[root@localhost ~]#

解決辦法:

修改配置文件/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..服務端沒有啓動

[root@wangying ~]# ps aux |grep mysql
root 11514 0.0 0.0 112704 964 pts/1 R+ 18:12 0:00 grep --color=auto mysql
[root@wangying ~]#
客戶端連接數據庫
[root@localhost ~]# 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)
[root@localhost ~]#

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

3.將/tmp/下的套接字文件刪除

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

[root@localhost init.d]#
這樣就需要將MySQL的服務器重新啓動,數據庫就能正常使用
[root@localhost init.d]# ./mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost init.d]# ./mysqld start
Starting MySQL. SUCCESS!
[root@localhost init.d]# ./mysqld status
SUCCESS! MySQL running (12026)
[root@localhost 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時,將配置文件中的套接字文件修改位置改變,會出現下面的問題,可以這樣解決
[root@localhost 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

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章