启动mysql时报错:

Starting mysqld daemon with databases from /var/lib/mysql
STOPPING server from pid file /var/run/mysqld/mysqld.pid
071112 00:22:06 mysqld ended

 

1 首先查看日志
#less /var/log/mysqld.log

其中有一段如下:

071112 0:22:06 [ERROR] /usr/local/mysql/bin/mysqld: Can't create/write to file '/var/run/mysqld/mysqld.pid' (Errcode: 2)
071112 0:22:06 [ERROR] Can't start server: can't create PID file: No such file or directory
071112 00:22:06 mysqld ended

 

 

 

 

说明/var/run/mysqld/mysqld.pid不存在

 

2  创建上面没有的文件
#cd /var/run/
#ls

mysqld目录不存在,创建它:

#mkdir /var/run/mysqld
#cd /var/run/mysqld

创建文件mysqld.pid:

 

#touch mysqld.pid

3 回到上一级目录,更改mysqld及其子目录的权限
#cd..
#chown -R mysql mysqld .
4 回到MySQL所在目录,启动MySQL试试
#cd /usr/local/mysql/
#bin/mysqld_safe --user=mysql &
nohup: ignoring input and redirecting stderr to stdout
Starting mysqld daemon with databases from /var/lib/mysql

能正常启动
5 此时MySQL服务可以正常启动,但是登录时有报错
#bin/mysqladmin -u root password root

又出错

[root@localhost mysql]# bin/mysqladmin -u root password root
bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

[root@localhost mysql]# bin/mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

分析:是/tmp/mysql.sock 不存在

 

6 解决方案
# cd /var/lib/mysql/

 

由于mysql 默认的mysql.sock 是在/var/lib/mysql/mysql.sock,创建符号连接:

 

# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock

 

7 再次连接试试,这次成功了!!!
# bin/mysql -u root
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 5.0.45 MySQL Community Server (GPL)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

 

mysql>

8 环境变量配置
①配置用户变量在【/当前用户文件夹/.bash_profile】文件中更改:

export PATH=/home/mysql-5.6.36/bin:$PATH

然后,保存退出,【source .bash_profile】

②配置系统变量

在【/etc/profile】文件进行上述设置
---------------------
作者:ADreamClusive
来源:CSDN
原文:https://blog.csdn.net/u013943420/article/details/72123960
版权声明:本文为博主原创文章,转载请附上博文链接!

发表评论

邮箱地址不会被公开。 必填项已用*标注