mysql关于用户密码的设置( 修改、重置、找回)
2015-01-04 20:12
645 查看
1.登录mysql
1.1单实例登录1) mysql 刚装完mysql无密码情况下登录2) mysql–u root 刚装完mysql无密码情况下登录 3) mysql–u root –p 标准的dba登录3) mysql–u root –p ‘密码’ 无交互登录。一般不用,容易泄漏密码登录成功后 提示:mysql>1.2 多实例登录 mysql –u root –S 指定mysql.sock文件的位置 提示:和单实例唯一的区别是多实例需要指定mysql.sock的位置2.修改用户密码
1.1交互式修改root密码
单实例:mysqladmin–u root –p password ‘新密码’
多实例:mysqladmin –u root –p password ‘新密码’ -S mysql.sock的位置
单实例:mysqladmin –u root –p‘旧密码’ password ‘新密码’(注意-p后面无空格)
多实例:mysqladmin –u root –p‘旧密码’ password ‘新密码’ -S mysql.sock的位置
3.1关闭mysql
1.1单实例登录1) mysql 刚装完mysql无密码情况下登录2) mysql–u root 刚装完mysql无密码情况下登录 3) mysql–u root –p 标准的dba登录3) mysql–u root –p ‘密码’ 无交互登录。一般不用,容易泄漏密码登录成功后 提示:mysql>1.2 多实例登录 mysql –u root –S 指定mysql.sock文件的位置 提示:和单实例唯一的区别是多实例需要指定mysql.sock的位置2.修改用户密码
1.1交互式修改root密码
单实例:mysqladmin–u root –p password ‘新密码’
[root@Mysql ~]# mysqladmin -u root -p password 'jeck123' Enter password: ----->输入旧密码
多实例:mysqladmin –u root –p password ‘新密码’ -S mysql.sock的位置
[root@Mysql ~]# mysqladmin -u root -p password 'jeck123' -S/usr/local/mysql/tmp/mysql.sock Enter password: ----->输入旧密码注意:若刚装完mysql,则root密码为空,直接回车即可1.2非交互式修改root密码
单实例:mysqladmin –u root –p‘旧密码’ password ‘新密码’(注意-p后面无空格)
[root@Mysql ~]# mysqladmin -uroot -p'jeck123' password '123jeck'
多实例:mysqladmin –u root –p‘旧密码’ password ‘新密码’ -S mysql.sock的位置
[root@Mysql ~]# mysqladmin -uroot -p'jeck123' password '123jeck'-S /usr/local/mysql/tmp/mysql.sock这种用于非交互式修改密码,适用于脚本1.3在mysql数据库中修改密码方法一:(只能修改当前登录mysql用户的密码)
[root@Mysql ~]# mysql -uroot -p123jeck Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 4 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou 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> setpassword=password('456jeck'); Query OK, 0 rows affected (0.00 sec) mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql> exit方法二:(可以修改任意用户的密码,只要有修改权限)
[root@Mysql ~]# mysql -uroot -p456jeck Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 6 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou 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> updatemysql.user set password=PASSWORD('789jeck') where user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed:3 Warnings: 0 mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql>3.找回用户密码
3.1关闭mysql
[root@Mysql~]# service mysqld stop Shuttingdown MySQL. SUCCESS! [root@Mysql ~]# netstat -lnt | grep mysqld3.2用mysqld_safe启动mysql,需要加—skip-grant-tables(忽略授权验证)单实例:
[root@Mysql~]# /usr/local/mysql/bin/mysqld_safe--skip-grant-tables & --->加&,使进程在后台运行 [1]28643 15010315:56:25 mysqld_safe Logging to '/usr/local/mysql-5.1.56/data/Mysql.err'. 15010315:56:25 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql-5.1.56/data [root@Mysql ~]# mysql -uroot -p Enter password: ---->直接回车,因为已经忽略验证 Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 1 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou 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> setpassword=password('jeck123'); --->此方法不行 ERROR 1290 (HY000): The MySQL server is running with the--skip-grant-tables option so it cannot execute this statement mysql> updatemysql.user set password=PASSWORD('jeck123') where user='root'; Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed:3 Warnings: 0 mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye多实例:
[root@Mysql~]# /usr/local/mysql/bin/mysqld_safe--defaults-file=/etc/my.cnf --skip-grant-tables & [1]28643 15010315:56:25 mysqld_safe Logging to '/usr/local/mysql-5.1.56/data/Mysql.err'. 15010315:56:25 mysqld_safe Starting mysqld daemon with databases from/usr/local/mysql-5.1.56/data [root@Mysql ~]# mysql -uroot -p -S/usr/local/mysql/tmp/mysql.sock Enter password: ---->直接回车,因为已经忽略验证 Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 1 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou 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> updatemysql.user set password=PASSWORD('jeck123') where user='root'; ---->修改root密码 Query OK, 3 rows affected (0.00 sec) Rows matched: 3 Changed:3 Warnings: 0 mysql> flushprivileges; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye3.3重新启动mysql(必须重新启动)
[root@Mysql~]# service mysqld restart Shuttingdown MySQL.150103 16:07:17 mysqld_safe mysqld from pid file/usr/local/mysql-5.1.56/data/Mysql.pid ended SUCCESS! StartingMySQL. SUCCESS! [1]+ Done /usr/local/mysql/bin/mysqld_safe --skip-grant-tables3.4用新修改的密码就可以登录了
[root@Mysql~]# mysql -uroot -pjeck123 Welcometo the MySQL monitor. Commands end with; or \g. YourMySQL connection id is 1 Serverversion: 5.1.56-log Source distribution Copyright(c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. Thissoftware comes with ABSOLUTELY NO WARRANTY. This is free software, andyou 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>
相关文章推荐
- linux mysql 找回密码设置字符集以及重置mysql
- Linux下Mysql增加用户,设置用户权限及修改密码的方法
- Mysql用户密码设置修改和权限分配(转载)
- 重置mysql Root用户密码及修改默认字符集一般就算设置了表的默认字符集为utf8并且通过UTF-8编码发送查询,你会发现存入数据库的仍然是乱码。问题就出在这个connection连接层上。 解决
- 设置、修改mysql用户密码
- Mysql用户密码设置修改和权限分配
- MySql 5.7中添加用户,新建数据库,用户授权,删除用户,修改密码,导入导出sql文件,设置字符集
- mysql用户密码修改,用户添加、删除、设置权限及源文件恢复数据库
- MySQL 修改用户密码及重置root密码
- 关于mysql清除密码、重置用户
- 关于MySQL下修改root用户密码的解决
- MySQL 修改用户密码及重置root密码
- MySQL中修改密码、编码设置、创建新用户、删除新用户以及备份等指令
- Mysql用户密码设置修改和权限分配
- Mysql 修改(设置) root 用户密码的方式[转载自百度经验]
- MySQL 修改用户密码及重置root密码
- 关于Windows系统MySQL5.6数据库root用户密码重置的注意事项
- Mysql用户密码设置修改和权限分配
- Mysql用户密码设置修改和权限分配
- Mysql用户密码设置修改和权限分配