hellopasswd
更改root密码
- /usr/local/mysql/bin/mysql -uroot
- 更改环境变量PATH,增加mysql绝对路径
- mysqladmin -uroot passwd ’123456‘
- mysql -uroot -p123456
- 密码重置
- vi /etc/my.cnf #
- 重启mysql服务 /etc/init.d/mysqld restart
- mysql -uroot
- use mysql;
- update user set password=password('aminglinux') where user='root';
[root@localhost ~]# ps aux | grep mysqlroot 2433 0.0 0.0 115392 1704 ? S 22:54 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysq --pid-file=/data/mysql/localhost.localdomain.pidmysql 2572 0.1 24.2 1300784 454492 ? Sl 22:54 0:04 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/localhost.localdomain.err --pid-file=/data/mysql/localhost.localdomain.pid --socket=/tmp/mysql.sockroot 3133 0.0 0.0 112664 976 pts/0 S+ 23:45 0:00 grep --color=auto mysql[root@localhost ~]# mysql -urootERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)[root@localhost ~]# ls /usr/local/mysql/bin/mysql/usr/local/mysql/bin/mysql[root@localhost ~]# export PATH=$PATH:/usr/local/mysql/bin/
进入mysql
[root@localhost ~]# mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.36 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quitBye
[root@localhost ~]# /usr/local/mysql/bin/mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.36 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quitBye
永久生效环境变量
[root@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile[root@localhost ~]# source /etc/profile
使用quit退出mysql终端
mysql> quitBye
设置mysql的root密码
[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -uroot password 123Warning: Using a password on the command line interface can be insecure.
警告大致意思是说密码用明文显示,不安全
登录mysql
[root@localhost ~]# /usr/local/mysql/bin/mysql -urootERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
拒绝登录,需要密码
-p使用密码登录
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.6.36 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quitBye
修改登录密码
[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -uroot -p'123' password '456'Warning: Using a password on the command line interface can be insecure.
指定密码登录
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p'456'Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.6.36 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quitBye
使用分号可以区分特殊符号
忘记密码
[root@localhost ~]# vi /etc/my.cnf添加 2 skip-grant
忽略授权
[root@localhost ~]# vi /etc/my.cnf 1 [mysqld] 2 skip-grant 3 datadir=/data/mysql 4 socket=/tmp/mysql.sock 5 # Disabling symbolic-links is recommended to prevent assorted security risks 6 symbolic-links=0 7 # Settings user and group are ignored when systemd is used. 8 # If you need to run mysqld under a different user or group, 9 # customize your systemd unit file for mariadb according to the 10 # instructions in http://fedoraproject.org/wiki/Systemd 11 12 [mysqld_safe] 13 #log-error=/var/log/mariadb/mariadb.log 14 #pid-file=/var/run/mariadb/mariadb.pid 15 16 # 17 # include all files from the config directory 18 # 19 #!includedir /etc/my.cnf.d[root@localhost ~]# /etc/init.d/mysqld restartShutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS![root@localhost ~]# /usr/local/mysql/bin/mysql -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.36 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql>
使用mysql库查看用户密码表
mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> select * from user;+-----------------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+| Host | User | Password | Select_priv | Insert_priv | Update_priv | Delete_priv | Create_priv | Drop_priv | Reload_priv | Shutdown_priv | Process_priv | File_priv | Grant_priv | References_priv | Index_priv | Alter_priv | Show_db_priv | Super_priv | Create_tmp_table_priv | Lock_tables_priv | Execute_priv | Repl_slave_priv | Repl_client_priv | Create_view_priv | Show_view_priv | Create_routine_priv | Alter_routine_priv | Create_user_priv | Event_priv | Trigger_priv | Create_tablespace_priv | ssl_type | ssl_cipher | x509_issuer | x509_subject | max_questions | max_updates | max_connections | max_user_connections | plugin | authentication_string | password_expired |+-----------------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+| localhost | root | *531E182E2F72080AB0740FE2F2D689DBE0146E04 | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | N || localhost.localdomain | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | N || 127.0.0.1 | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | N || ::1 | root | | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | Y | | | | | 0 | 0 | 0 | 0 | mysql_native_password | | N || localhost | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | mysql_native_password | NULL | N || localhost.localdomain | | | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | N | | | | | 0 | 0 | 0 | 0 | mysql_native_password | NULL | N |+-----------------------+------+-------------------------------------------+-------------+-------------+-------------+-------------+-------------+-----------+-------------+---------------+--------------+-----------+------------+-----------------+------------+------------+--------------+------------+-----------------------+------------------+--------------+-----------------+------------------+------------------+----------------+---------------------+--------------------+------------------+------------+--------------+------------------------+----------+------------+-------------+--------------+---------------+-------------+-----------------+----------------------+-----------------------+-----------------------+------------------+6 rows in set (0.00 sec)
mysql> select password from user where user='root';+-------------------------------------------+| password |+-------------------------------------------+| *531E182E2F72080AB0740FE2F2D689DBE0146E04 || || || |+-------------------------------------------+4 rows in set (0.00 sec)
mysql> select password from user;+-------------------------------------------+| password |+-------------------------------------------+| *531E182E2F72080AB0740FE2F2D689DBE0146E04 || || || || || |+-------------------------------------------+6 rows in set (0.00 sec)
更改用户密码表
mysql> update user set password=password('123') where user='root';Query OK, 4 rows affected (0.00 sec)Rows matched: 4 Changed: 4 Warnings: 0mysql> quitBye[root@localhost ~]# vi /etc/my.cnf删除 2 skip-grant
[root@localhost ~]# vi /etc/my.cnf 1 [mysqld] 2 datadir=/data/mysql 3 socket=/tmp/mysql.sock 4 # Disabling symbolic-links is recommended to prevent assorted security risks 5 symbolic-links=0 6 # Settings user and group are ignored when systemd is used. 7 # If you need to run mysqld under a different user or group, 8 # customize your systemd unit file for mariadb according to the 9 # instructions in http://fedoraproject.org/wiki/Systemd 10 11 [mysqld_safe] 12 #log-error=/var/log/mariadb/mariadb.log 13 #pid-file=/var/run/mariadb/mariadb.pid 14 15 # 16 # include all files from the config directory 17 # 18 #!includedir /etc/my.cnf.d[root@localhost ~]# /etc/init.d/mysqld restartShutting down MySQL.... SUCCESS! Starting MySQL. SUCCESS!
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p123Warning: Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.6.36 MySQL Community Server (GPL)Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> quitBye
更改密码中出现的错误
mysql> update user set password=password('123') where user='root';ERROR 1046 (3D000): No database selected
需要更改用户密码前使用mysql库use mysql;
mysql> use mysql;Reading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase changedmysql> update user set password=password('123') where user='root';Query OK, 4 rows affected (0.00 sec)Rows matched: 4 Changed: 4 Warnings: 0mysql> quitBye
修改于 180112