MySQL login and setup password steps in Linux

Source: Internet
Author: User
Tags flush mysql login


MySQL login and set password under Linux (this article is based on centos6.4, mysql5.7.3), MySQL installed in the/usr/local/mysql directory:

[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 #建议此种方式, the latter does not recommend/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 insecure.
[Root@lnmp ~]#/usr/local/mysql/bin/mysql-uroot-p ' admin123 '
MySQL: [Warning] Using a password on the command line interface can is 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; #如果不更新, the new password does not take effect
Mysql> set Password=password (' admin123 '); #以上方法适用于已知密码或者已经登入到msyql the case of!!! >
Query OK, 0 rows Affected (0.00 sec)
mysql> flush Privileges;
Query OK, 0 rows Affected (0.00 sec)
Forget the MySQL root password:

[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 #跳过授权表后, restart MySQL
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; #刷新权限, password modified to 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

Note: You can add/usr/local/mysql/bin to the path. This allows you to directly enter MySQL or mysqladmin without entering the full path

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.