linux中Mysql的登陆与设置密码步骤
2019/10/10/17:32:37 阅读:2439 来源:谷歌SEO算法 标签:
谷歌CEO
Mysql密码我们如果安装时没有设置也可以在命令模式下进行设置了,下面来为各位介绍linux中Mysql的登陆与设置密码步骤吧,希望例子对各位有帮助.
linux下Mysql的登陆与设置密码(本文基于centos6.4、mysql5.7.3),mysql安装在/usr/local/mysql目录下:
- [root@lnmp~]#/usr/local/mysql/bin/mysqladmin-urootpassword'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]Usingapasswordonthecommandlineinterfacecanbeinsecure.
- [root@lnmp~]#/usr/local/mysql/bin/mysql-uroot-p'admin123'
- mysql:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.
- ERROR1045(28000):Accessdeniedforuser'root'@'localhost'(usingpassword:YES)
- [root@lnmp~]#/usr/local/mysql/bin/mysql-uroot-p'admin456'
- mysql>
- mysql>updatemysql.usersetpassword=PASSWORD('admin123')whereuser='root';#升级用户表中的密码
- QueryOK,4rowsaffected(0.03sec)
- Rowsmatched:4Changed:4Warnings:0
- mysql>flushprivileges;#如果不更新,则新密码不生效
- mysql>setpassword=password('admin123');#以上方法适用于已知密码或者已经登入到msyql>的情况下!!!
- QueryOK,0rowsaffected(0.00sec)
- mysql>flushprivileges;
- QueryOK,0rowsaffected(0.00sec)
- 忘记mysql的root密码:
- [root@lnmp~]#servicemysqldstop#关闭mysql
- ShuttingdownMySQL...SUCCESS!
- [root@lnmp~]#/usr/local/mysql/bin/mysqld_safe--skip-grant-tables&#跳过授权表
- [1]3692
- [root@lnmp~]#14050215:40:48mysqld_safeLoggingto'/byrd/server/mysql-5.7.3/data/lnmp.err'.
- 14050215:40:48mysqld_safeStartingmysqlddaemonwithdatabasesfrom/byrd/server/mysql-5.7.3/data
- [root@lnmp~]#/etc/init.d/mysqldstart#跳过授权表后,重新启动mysql--phpfensi.com
- StartingMySQLSUCCESS!
- [root@lnmp~]#/usr/local/mysql/bin/mysql#直接进入mysql
- WelcometotheMySQLmonitor.Commandsendwith;org.
- mysql>updatemysql.usersetpassword=PASSWORD('admin123')whereuser='root';#修改需要的mysql的root密码
- mysql>flushprivileges;#刷新权限,密码修改为admin123
- mysql>quit
- [root@lnmp~]#/etc/init.d/mysqldstop
- [root@lnmp~]#/etc/init.d/mysqldstart
- [root@lnmp~]#/usr/local/mysql/bin/mysql-uroot-p'admin123'#密码被修改为了admin123
备注:你可以将/usr/local/mysql/bin加入PATH中,这样可以直接输入mysql或者mysqladmin,不用输入全路径.
热门评论