博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【CentOS 7MySQL常用操作1】,更改root密码#180112
阅读量:6659 次
发布时间:2019-06-25

本文共 15985 字,大约阅读时间需要 53 分钟。

hot3.png

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

转载于:https://my.oschina.net/hellopasswd/blog/1606306

你可能感兴趣的文章
【转】Java:Session详解
查看>>
LeetCode - 101. 对称二叉树
查看>>
HTTP 状态码详解
查看>>
学习笔记——STORAGE STRUCTURE
查看>>
lvm基本应用
查看>>
TabHost页和子Activity之间的通讯
查看>>
将数字金额转化为汉字表示
查看>>
现在该怎么去做SEO?
查看>>
图片涂鸦
查看>>
Shell脚本编程之Bash特性-IO重定向-变量
查看>>
东禹鲜锅-您的饮食乐趣
查看>>
windows系统常用快捷键
查看>>
php的数据类型
查看>>
nginx编译安装
查看>>
详解JSP九个内置对象
查看>>
linux - RAID技术
查看>>
错误异常slice indices must be integers or None or have
查看>>
我的友情链接
查看>>
drbd+heartbeat+nfs
查看>>
下载各种视频的好方法
查看>>