1:
[root@localhost ~]# mysql -u root
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket 'mysql.mysql' (2)
解决方法:1:在/etc/my.cnf里找到socket选项,看指定的位置是否有误。在数据安装目录下面找到mysql.mysql ,比如我的数据库文件安装是在/data/mysqldb,然后使用ln -s /data/mysqldb/mysql.mysql /usr/local/mysql 即可。mysql.mysql是mysql的socket, 虽然数据库文件所在的目录已经有这个socket,但是mysql安装目录也需要有,否则报错。
2:[root@localhost ~]# mysql -u root -p
MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)
这个有可能是mysql的user表里面,有密码为空的用户。
[root@localhost ~]# mysql -u root
mysql> use mysql
Database changed
mysql>update user set password=password("123456") where user="root";
mysql> delete from user where password='';
mysql>flush privileges;
3:
[root@localhost ~]# mysql -u root -p
MYSQL ERROR 1045 (28000): Access denied for user (using password: YES)
[root@localhost ~]# mysql -u root
MYSQL ERROR 1045 (28000): Access denied for user (using password: NO)
这个可能是数据库mysql的user表没有用户导致的。
[root@localhost ~]# service mysqld stop
[root@localhost ~]# mysqld_safe --skip-grant-tables
ctrl+z
mysql> INSERT INTO user(host, user, password, select_priv, insert_priv, update_priv,ssl_cipher,x509_issuer,x509_subject) VALUES ('localhost', 'root‘,PASSWORD('123456'), 'Y', 'Y','Y','','','');
mysql> update user set Host='localhost',select_priv='y', insert_priv='y',update_priv='y', Alter_priv='y',delete_priv='y',create_priv='y',drop_priv='y',reload_priv='y',shutdown_priv='y',Process_priv='y',file_priv='y',grant_priv='y',References_priv='y',index_priv='y',create_user_priv='y',show_db_priv='y',super_priv='y',create_tmp_table_priv='y',Lock_tables_priv='y',execute_priv='y',repl_slave_priv='y',repl_client_priv='y',create_view_priv='y',show_view_priv='y',create_routine_priv='y',alter_routine_priv='y',create_user_priv='y' where user='root';
mysql>exit;
[root@localhost ~]#killall mysqld_safe;