PS:高版本的mysql可能不适用本文
mysqladmin -u root password
,连续输入两次新密码mysqladmin -u root password -p 原密码
,连续输入两次新密码alter user 'root'@'localhost' identified by '新密码';
注意:5.7版本下的mysql数据库下已经没有password这个字段了,password
字段改成了authentication_string
show databases;
drop database test;
use mysql;
delete from user where not (user='root');
delete from user where user='root' and password='';
flush privileges;
使用update更新mysql库中user表中的信息
use mysql;
update user set user='hehao' where user='root';
flush privileges;
注意:Mysql8.0之前的版本中,加密规则是mysql_native_password
,而在Mysql8之后,加密规则是caching_sha2_password
添加账户test,密码进行加密处理
use mysql;
insert into users values (1,password(123456),'test');
Linux下修改my.cnf
文件
vim /etc/my.cnf
加入如下内容
[mysqld]
user=mysql
Linux下修改my.cnf
文件,去掉注释符号
vim /etc/my.cnf
加入如下内容
[mysqld]
max_connections=5
max_user_connections=2
或者限制某个用户,在mysql中执行
grant test on *.* to testdb@localhost max_user_connections 2;
修改my.cnf
文件,去掉注释符号
vim /etc/my.cnf
修改内容如下
skip-networking
.mysql_history
ln -s /dev/null /root/.mysql_history
mysql -u root -p 明文密码 //直接输入明文密码
mysql -u root -p //回车后输入隐藏密码
修改my.cnf
文件,加入关闭信息
vim /etc/my.cnf
加入如下内容
[mysqld]
local_infile=0
或者添加启动选项
用脚本开启mysql
mysql_safe --local_infile=0 --user=mysql
use mysql
update user set File_priv='N' where user='用户名';
grep secure_file_priv /etc/my.cnf
secure_file_priv=xxx路径
手动备份数据库可以防止密码明文储存
mysqldump --user=root --all-databases --flush-privileges --lock-all-tables \ --master-data=1 --flush-logs --triggers --routines --events \ --hex-blob > 备份路径/文件名时间戳.sql
还原数据库
mysql -u 用户名 -p 密码 数据库名<备份的文件名