原码安装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

 

猜你喜欢

转载自blog.csdn.net/qq_37194598/article/details/84627620