版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/myq151/article/details/83930205
使用Ubuntu16.04出现的问题: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 ‘/var/run/mysqld/mysqld.sock’ (2),原因是因为丢失mysqld.sock文件。
xxx@ubuntu:~$ mysql -uroot -pmysql
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 '/var/run/mysqld/mysqld.sock' (2)
终端输入mysql -uroot -h 127.0.0.1 -p
xxx@ubuntu:~$ mysql -uroot -h 127.0.0.1 -p
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1' (111)
显然,也没有用。
进入,
cd /etc/mysql/mysql.conf.d
xxx@ubuntu:/etc/mysql/mysql.conf.d$ ls
mysqld.cnf mysqld_safe_syslog.cnf
xxx@ubuntu:/etc/mysql/mysql.conf.d$ vim mysqld.cnf
进入mysql.cnf文件,如下:
然后保存退出,并将这个目录权限修改一下:
/etc/mysql/mysql.conf.d$ sudo chmod 777 mysqld.cnf
然后就启动mysql 和mysqld 服务:
xxx@ubuntu:/etc/mysql/mysql.conf.d$ service mysql restart
xxx@ubuntu:/etc/mysql/mysql.conf.d$ service mysqld restart
然而,mysqld启动又出错了,启动失败,愤怒啊!!!不用管它!
xxx@ubuntu:~$ service mysqld restart
Failed to restart mysqld.service: Unit mysqld.service not found.
进入目录并查看:
xxx@ubuntu:/var/run$ cd mysqld/
xxx@ubuntu:/var/run/mysqld$ ls
mysqld.sock mysqld.sock.lock
然后使用当前的 mysqld.sock 测试一下:
xxx@ubuntu:/var/run/mysqld$ mysql -uroot -p -S /var/run/mysqld/mysqld.sock
此时,终于见到光明了。可以正常进入mysql数据库。
xxx@ubuntu:/var/run/mysqld$ mysql -uroot -p -S /var/run/mysqld/mysqld.sock
mysql: [Warning] World-writable config file '/etc/mysql/mysql.conf.d/mysqld.cnf' is ignored.
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.24-0ubuntu0.16.04.1 (Ubuntu)
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>
到此还不算完成!
建立软链接:
xxx@ubuntu:~$ ln -s /var/run/mysqld/mysqld.sock /var/lib/mysql/mysql.sock
进入如下目录:
xxx@ubuntu:~$ cd /var//run/mysqld/
xxx@ubuntu:/var/run/mysqld$ ls
mysqld.sock mysqld.sock.lock
然后再将原来修改的 mysql.cnf 文件改回来,
至此,算是完成了。
重新进入终端测试一下:
此时,成功搞定!今日什么也没有做,花了近一天的时间,才完成这个大bug的!!!