【CentOS 7MySQL經常使用操做1】,更改root密碼#180112

hellopasswdmysql


更改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 mysql
root       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.pid
mysql      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.sock
root       3133  0.0  0.0 112664   976 pts/0    S+   23:45   0:00 grep --color=auto mysql
[root@localhost ~]# mysql -uroot
ERROR 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/

進入mysqllinux

[root@localhost ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

永久生效環境變量sql

[root@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
[root@localhost ~]# source /etc/profile

使用quit退出mysql終端安全

mysql> quit
Bye

設置mysql的root密碼dom

[root@localhost ~]# /usr/local/mysql/bin/mysqladmin -uroot password 123
Warning: Using a password on the command line interface can be insecure.

警告大體意思是說密碼用明文顯示,不安全socket

登陸mysqlui

[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

拒絕登陸,須要密碼this

-p使用密碼登陸spa

[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

修改登陸密碼rest

[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 8
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

使用分號能夠區分特殊符號

忘記密碼

[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 restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

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 names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 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: 0

mysql> quit
Bye
[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 restart
Shutting down MySQL.... SUCCESS! 
Starting MySQL. SUCCESS!
[root@localhost ~]# /usr/local/mysql/bin/mysql -uroot -p123
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 1
Server 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 its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

更改密碼中出現的錯誤

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 names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password('123') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> quit
Bye

修改於 180112

相關文章
相關標籤/搜索