MySQL常用操作--更改mysql密码

MySQL常用操作

更改mysql密码

1.更改环境变量

修改/etc/profile 文件,文件尾添加 mysql 的绝对路径

[root@localhost mysql]# tail -1 /etc/profile

export PATH=$PATH:/usr/local/mysql/bin/

[root@localhost mysql]# source /etc/profile

或者直接添加

[root@localhost mysql]# mysql -uroot

-bash: mysql: command not found

[root@localhost mysql]# export PATH=$PATH:/usr/local/mysql/bin/

[root@localhost mysql]# mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.43 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2019, 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>

 

 

2.创建密码

[root@localhost mysql]# mysqladmin -uroot password '000000'

Warning: Using a password on the command line interface can be insecure.

注释:可以忽略 warning 内容,指的是明码输入屏幕不安全。

[root@localhost mysql]# mysql -uroot -p000000

 

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

 

mysql>

 

 

 

3.重置密码

修改配置文件/etc/my.cnf,在 mysqld 配置段,增加字段 skip-grant

[mysqld]

skip-grant    //忽略授权

# Remove leading # and set to the amount of RAM for the most important data

# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size = 128M

 

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

 

修改完成后,重启 mysql 服务

之后可以不适用密码直接登录

[root@localhost ~]# /etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

 

[root@localhost ~]# mysql -uroot

Welcome to the MySQL monitor.  Commands end with ; or \g.

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>

mysql> update user set password=password('linux') where user='root';

Query OK, 4 rows affected (0.00 sec)

Rows matched: 4  Changed: 4  Warnings: 0

 

 

修改完成后,把/etc/my.cnf 改回原有状态,并重启 mysql服务。

[root@localhost ~]# /etc/init.d/mysqld restart

Shutting down MySQL.. SUCCESS!

Starting MySQL. SUCCESS!

 

[root@localhost ~]# mysql -uroot -plinux

Warning: Using a password on the command line interface can be insecure.

Welcome to the MySQL monitor.  Commands end with ; or \g.

 

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

 

mysql>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值