您的位置:首页 > 博客中心 > 数据库 >

Mysql学习之--修改root用户口令

时间:2022-03-14 00:14

Mysql学习之--修改root用户口令

在mysql系统外,使用mysqladmin
Enter password: 【输入原来的密码】

通过登录mysql系统,
Enter password: 【输入原来的密码】
mysql>mysql> mysql> mysql> 
     首先,你必须要有操作系统的root权限了。要是连系统的root权限都没有的话,先考虑root系统再走下面的步骤。
类似于安全模式登录系统,有人建议说是/etc/init.d/mysqld status
mysqld dead but subsys locked
这样即使你是在安全模式下启动mysql都未必会有用的,所以一般是这样&,表示在后台运行,不再后台运行的话,就再打开一个终端咯。
mysql> mysql> mysql> mysql> exit;      

案例:

[root@ogg ~]# mysqld_safe --skip-grant-tables &
[1] 3117
[root@ogg ~]# 140924 14:03:30 mysqld_safe Logging to ‘/var/lib/mysql/ogg.err‘.
140924 14:03:30 mysqld_safe A mysqld process already exists
[1]+  Exit 1                  mysqld_safe --skip-grant-tables

关闭mysql server:
[root@ogg ~]# service mysql stop
Shutting down MySQL..                                      [  OK  ]

[root@ogg ~]# mysqld_safe --skip-grant-tables &
[1] 3243
[root@ogg ~]# 140924 14:03:48 mysqld_safe Logging to ‘/var/lib/mysql/ogg.err‘.
140924 14:03:48 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@ogg ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.47-log 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> use mysql
Database changed

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
29 rows in set (0.00 sec)

mysql> update user set password=PASSWORD(‘oracle‘) where user=‘root‘;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 4  Changed: 3  Warnings: 0

mysql> flush privileges;
ERROR 1033 (HY000): Incorrect information in file: ‘./mysql/tables_priv.frm‘

mysql> exit
Bye

[root@ogg ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.47-log 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>

错误信息:   

[root@ogg mysql]# mysqld_safe --skip-grant-tables &

[1] 3795

[root@ogg mysql]# 140924 14:15:09 mysqld_safe Logging to ‘/var/lib/mysql/ogg.err‘.
140924 14:15:09 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
[root@ogg mysql]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.47-log 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> use mysql
Database changed

mysql> flush privileges;

ERROR 1033 (HY000): Incorrect information in file: ‘./mysql/tables_priv.frm‘

mysql> exit

Bye

[root@ogg mysql]# service mysql stop
Shutting down MySQL.....140924 14:15:44 mysqld_safe mysqld from pid file /var/lib/mysql/ogg.pid ended
                                                           [  OK  ]
[1]+  Done                    mysqld_safe --skip-grant-tables

[root@ogg mysql]# service mysql start
Starting MySQL..     
                                      [  OK  ]
                                      
正常连接:                                      
[root@ogg mysql]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.4-m7-log 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> use mysql;
Database changed
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>


                

本文出自 “” 博客,请务必保留此出处

热门排行

今日推荐

热门手游