[root@test1 local]# mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1 to server version: 4.0.16-standard
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql>
出现了“mysql>”提示符。
增加了密码后的登录格式如下:
mysql -u root -p
Enter password: (输入密码)
其中-u后跟的是用户名,-p要求输入密码,回车后在输入密码处输入密码。
如果root用户设置了密码,并且我们不知道root用户的密码,当我们在Linux中使用mysql命令登录时,会报错ERROR 1045 (28000): Access denied for user root@localhost (using password: NO)
解决办法;
1、停用mysql服务:# /etc/rc.d/init.d/mysqld stop
2、输入命令:# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
3、登入数据库:# mysql -u root mysql 4、mysql> use mysql;结果如下: Database changed
5、mysql> UPDATE user SET Password=PASSWORD('newpassword')where USER='newuser'; 结果如下:
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql>FLUSH PRIVILEGES; 结果如下:
Query OK, 0 rows affected (0.00 sec)
mysql> quit
# /etc/init.d/mysql restart
# mysql -u newuser–p
Enter password:newpassword
mysql><登录成功>
如果我们需要修改数据库用户的密码,我们可以这样做
方法1:
在mysql系统外,使用mysqladmin
# mysqladmin
-u root -p password "test123"
Enter password: 【输入原来的密码】
方法2:
通过登录mysql系统,
# mysql -uroot
-p
Enter password: 【输入原来的密码】
mysql>use
mysql;
mysql> update
user set password=passworD("test") where user='root';
mysql> flush
privileges;
mysql> exit;
本文介绍了MySQL数据库的登录命令及语法,并详细说明了如何在忘记密码的情况下重置MySQL的root用户密码,同时还提供了两种更新数据库用户密码的方法。
1978

被折叠的 条评论
为什么被折叠?



