mysql 安装后无法登陆mysql的 shell 那mysql>经验:ERROR 1045 (28000): Access denied for user 'root'@'localhost‘
2015-06-20 10:02
639 查看
[root@hzswtb2-mpc ~]# mysql
ERROR 1045 (28000): Access denied for user
'root'@'localhost' (using password: NO)
遇到:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
网上找了非常多的文章还是没有解决我的问题。
1.首先能够确认的是mysql 命令行 sql命令keyword是不区分大写和小写;在mysql 5.1.51版本号;
2.先将正常启动的mysqld stop掉;
3.再以绕过root口令检查的方式 启动 mysqld。
4.查询 user 表,发现user表是空的,insert 一个 root 用户, 关闭mysqld,正常启动mysqld,用root用户,新的password newpass 就能够登录 mysql shell 了
下面是解决经过:
1.先将正常启动的mysqld stop掉
[root@hzswtb2-mpc ~]# service mysqld stop
Stopping mysqld: [ OK ]
2.用绕过root口令检查的方式 启动 mysql server,而且让其在后台执行。
[root@hzswtb2-mpc ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 25513
[root@hzswtb2-mpc ~]# 141215 15:00:16 mysqld_safe Logging to '/var/log/mysqld.log'.
141215 15:00:16 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
3. mysql回车,进入mysql shell,依照前人留下的方法, update user表中的 root 用户的password,结果发现 0 rows affected,再select 细看 user 表是空的;
[root@hzswtb2-mpc ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.51 Source distribution
mysql> UPDATE user SET PASSWORD=PASSWORD('123456') where USER='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.00 sec)
mysql> select * from user;
Empty set (0.00 sec)
4.在user表 insert 一个名称为root的用户。
mysql> insert into user(Host,User,Password,Select_priv,Insert_priv) VALUES('localhost','root',PASSWORD('pass3'),'Y','Y');
Query OK, 1 row affected, 3 warnings (0.00 sec)
5.看到有个root用户了;
mysql> select * from user
-> ;
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv
| Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | ssl_type
| ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost | root | *35B5E90BC4F5AE5D02ED515DF6B61141F24EDA02 | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N
| N | N | N | N | N | N | N | N | N | N | N | N | N | N |
| | | | 0 | 0 | 0 | 0 |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
1 row in set (0.00 sec)
6 再更新 root 用户的password,也能返回成功了;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
7.stop 刚才的 mysql服务,以正常方式又一次启动mysql server。mysql -u root -p password是newpass
[root@hzswtb2-mpc ~]# service mysqld stop
141215 16:12:24 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld: [ OK ]
[1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@hzswtb2-mpc ~]# service mysqld start
Starting mysqld: [ OK ]
[root@hzswtb2-mpc ~]#
[root@hzswtb2-mpc ~]# mysql
ERROR 1045 (28000): Access denied for user
'root'@'localhost' (using password: NO)
[root@hzswtb2-mpc ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.51 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
ERROR 1045 (28000): Access denied for user
'root'@'localhost' (using password: NO)
遇到:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
网上找了非常多的文章还是没有解决我的问题。
1.首先能够确认的是mysql 命令行 sql命令keyword是不区分大写和小写;在mysql 5.1.51版本号;
2.先将正常启动的mysqld stop掉;
3.再以绕过root口令检查的方式 启动 mysqld。
4.查询 user 表,发现user表是空的,insert 一个 root 用户, 关闭mysqld,正常启动mysqld,用root用户,新的password newpass 就能够登录 mysql shell 了
下面是解决经过:
1.先将正常启动的mysqld stop掉
[root@hzswtb2-mpc ~]# service mysqld stop
Stopping mysqld: [ OK ]
2.用绕过root口令检查的方式 启动 mysql server,而且让其在后台执行。
[root@hzswtb2-mpc ~]# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
[1] 25513
[root@hzswtb2-mpc ~]# 141215 15:00:16 mysqld_safe Logging to '/var/log/mysqld.log'.
141215 15:00:16 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
3. mysql回车,进入mysql shell,依照前人留下的方法, update user表中的 root 用户的password,结果发现 0 rows affected,再select 细看 user 表是空的;
[root@hzswtb2-mpc ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.51 Source distribution
mysql> UPDATE user SET PASSWORD=PASSWORD('123456') where USER='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 0 Changed: 0 Warnings: 0
mysql> use mysql
Database changed
mysql> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
23 rows in set (0.00 sec)
mysql> select * from user;
Empty set (0.00 sec)
4.在user表 insert 一个名称为root的用户。
mysql> insert into user(Host,User,Password,Select_priv,Insert_priv) VALUES('localhost','root',PASSWORD('pass3'),'Y','Y');
Query OK, 1 row affected, 3 warnings (0.00 sec)
5.看到有个root用户了;
mysql> select * from user
-> ;
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv
| Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | ssl_type
| ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
| localhost | root | *35B5E90BC4F5AE5D02ED515DF6B61141F24EDA02 | Y | Y | N | N | N | N | N | N | N | N | N | N | N | N
| N | N | N | N | N | N | N | N | N | N | N | N | N | N |
| | | | 0 | 0 | 0 | 0 |
+-----------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+
1 row in set (0.00 sec)
6 再更新 root 用户的password,也能返回成功了;
mysql> UPDATE user SET Password = PASSWORD('newpass') WHERE user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
7.stop 刚才的 mysql服务,以正常方式又一次启动mysql server。mysql -u root -p password是newpass
[root@hzswtb2-mpc ~]# service mysqld stop
141215 16:12:24 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld: [ OK ]
[1]+ Done mysqld_safe --user=mysql --skip-grant-tables --skip-networking
[root@hzswtb2-mpc ~]# service mysqld start
Starting mysqld: [ OK ]
[root@hzswtb2-mpc ~]#
[root@hzswtb2-mpc ~]# mysql
ERROR 1045 (28000): Access denied for user
'root'@'localhost' (using password: NO)
[root@hzswtb2-mpc ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.51 Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
相关文章推荐
- Powershell目录文件夹管理权限的继承和指定方法
- PowerShell启用winrm失败:拒绝访问 0x80070005 -2147024891
- PowerShell隐藏不显示窗口的多种方法
- 不看后悔的Linux生产服务器Shell脚本分享
- (转载)Bash 中的特殊字符大全
- shell学习十九天----文本块排序
- Bash processing pipeline
- linux shell脚本学习xargs命令使用详解
- shell学习十八天----文本排序
- 线上问题排查命令----Shell篇
- 自己写shell命令pwd
- shell中vi替换特殊字符(制表符\t等)的方法
- shell是如何判断空格长度的??
- shell学习十七天----awk命令
- 终极 Shell
- Bash 中的特殊字符大全
- 如何使用Shell脚本编译生成Archive文件并导出签名IPA文件。
- shell脚本生成一个简单的计算器
- Powershell 自动化安装zabbix agent
- 解决删除大量文件的问题 -bash: /usr/bin/sudo: Argument list too long