linux中Mysql的登陆与设置密码步骤
发布:smiling 来源: PHP粉丝网 添加日期:2015-04-17 17:09:48 浏览: 评论:0
Mysql密码我们如果安装时没有设置也可以在命令模式下进行设置了,下面来为各位介绍linux中Mysql的登陆与设置密码步骤吧,希望例子对各位有帮助.
linux下Mysql的登陆与设置密码(本文基于centos6.4、mysql5.7.3),mysql安装在/usr/local/mysql目录下:
- [root@lnmp ~]# /usr/local/mysql/bin/mysqladmin -uroot password 'admin123' #修改mysql密码为admin123
- [root@lnmp ~]# /usr/local/mysql/bin/mysql #如果是空密码可以这样进入mysql
- [root@lnmp ~]# /usr/local/mysql/bin/mysql -uroot -p #建议此种方式,后面的不建议/usr/local/mysql/bin/mysql -uroot -p'admin123'
- [root@lnmp ~]# /usr/local/mysql/bin/mysqladmin -uroot -p'admin123' password 'admin456'
- mysqladmin: [Warning] Using a password on the command line interface can be insecure.
- [root@lnmp ~]# /usr/local/mysql/bin/mysql -uroot -p'admin123'
- mysql: [Warning] Using a password on the command line interface can be insecure.
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
- [root@lnmp ~]# /usr/local/mysql/bin/mysql -uroot -p'admin456'
- mysql>
- mysql> update mysql.user set password=PASSWORD('admin123') where user='root'; #升级用户表中的密码
- Query OK, 4 rows affected (0.03 sec)
- Rows matched: 4 Changed: 4 Warnings: 0
- mysql> flush privileges; #如果不更新,则新密码不生效
- mysql> set password=password('admin123'); #以上方法适用于已知密码或者已经登入到msyql>的情况下!!!
- Query OK, 0 rows affected (0.00 sec)
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
- 忘记mysql的root密码:
- [root@lnmp ~]# service mysqld stop #关闭mysql
- Shutting down MySQL... SUCCESS!
- [root@lnmp ~]# /usr/local/mysql/bin/mysqld_safe --skip-grant-tables & #跳过授权表
- [1] 3692
- [root@lnmp ~]# 140502 15:40:48 mysqld_safe Logging to '/byrd/server/mysql-5.7.3/data/lnmp.err'.
- 140502 15:40:48 mysqld_safe Starting mysqld daemon with databases from /byrd/server/mysql-5.7.3/data
- [root@lnmp ~]# /etc/init.d/mysqld start #跳过授权表后,重新启动mysql --phpfensi.com
- Starting MySQL SUCCESS!
- [root@lnmp ~]# /usr/local/mysql/bin/mysql #直接进入mysql
- Welcome to the MySQL monitor. Commands end with ; or g.
- mysql> update mysql.user set password=PASSWORD('admin123') where user='root'; #修改需要的mysql的root密码
- mysql> flush privileges; #刷新权限,密码修改为admin123
- mysql>quit
- [root@lnmp ~]# /etc/init.d/mysqld stop
- [root@lnmp ~]# /etc/init.d/mysqld start
- [root@lnmp ~]# /usr/local/mysql/bin/mysql -uroot -p'admin123' #密码被修改为了admin123
备注:你可以将/usr/local/mysql/bin加入PATH中,这样可以直接输入mysql或者mysqladmin,不用输入全路径.
Tags: Mysql登陆设置 Mysql设置密码
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)