mysql配置及一些知识记录

方文锋  2019-11-27 00:14:54  1352  首页学习MySQL

#首先,修改validate_password_policy参数的值

mysql> set global validate_password_policy=0;

#再修改密码的长度:

mysql> set global validate_password_length=1;

#查看密码的设定最小长度:

mysql> select @@validate_password_length;

#再次执行修改密码就可以了:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';



#允许外网 IP 访问[创建test用户,任意主机都可以访问,登录密码为password]

mysql> create user 'test'@'%' identified by 'password';

#允许本地 IP 访问 localhost, 127.0.0.1

mysql> create user 'test'@'localhsot' identified by 'password';



#授权root用户拥有所有数据库中所有的操作权限:

mysql> ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

#授权某个数据库用户(这里用test 表示数据库用户)拥有某个数据库(这里用testdb表示数据库名称)的所有权限(授予用户通过外网IP对于该数据库的全部权限):

mysql> grant all privileges on `testdb`.* to 'test'@'%' identified by 'password';

mysql> grant all privileges on testdb.* to 'test'@'%' identified by 'password';

mysql> grant all privileges on testdb.* to 'test'@'%';

#授权test用户拥有所有数据库的某些权限:[test用户对所有数据库都有select,delete,update,insert,create,drop 权限]

mysql> grant select,delete,update,insert,create,drop on *.* to 'test'@"%" identified by "password";

#授权test用户拥有所有数据库的所有权限(不包括给用户授权):

grant all privileges on *.* to 'test'@'%' identified by 'password';

#授权test用户拥有所有数据库的所有权限:

grant all privileges on *.* to 'test'@'%' identified by 'password' with grant option;

#刷新系统权限表

mysql>flush privileges;


#mysql删除用户的两种方法(drop 和 delete)

#drop user 用户名@'%';

#删除test用户(外网的, 'test'@'%'  这个用户)[注释:删除账户及权限]

mysql> drop user 'test'@'%';

#删除test用户(本地的, 'test'@'%'  这个用户)[注释:删除账户及权限]

mysql> drop user 'test'@'localhost';

#用delete 来删除test用户(本地)

mysql> delete FROM user Where User='test' and Host='localhost';

mysql> flush privileges;

#用delete 来删除test用户(外网)

mysql> delete FROM user Where User='test' and Host='%';

mysql> flush privileges;

#修改密码

mysql> update from user set password=password("password") where user='test' and host='localhost';

mysql> flush privileges;

或者mysql> set password for 'test'@'localhost' = password('password');


#查看指定数据库的大小,如查看数据库 db_name 

mysql> use information_schema;

mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='db_name';


#查看指定库的指定表的大小,如查看数据库 db_name 里面的表 table_01

mysql> use information_schema;

mysql> select concat(round(sum(DATA_LENGTH/1024/1024),2),'MB') as data  from TABLES where table_schema='db_name' and table_name='table_01';




#用本地CMD连接远程Mysql数据库(本地要安装Mysql数据库)

#mysql -uhello -pworld -h192.168.1.88 -P3306 -Dmysql_oa

#mysql -u用户名 -p密码 -h远程数据库IP地址 -P端口 -D数据库名

#mysql -u 用户名 -p 密码 -h 远程数据库IP地址 -P 端口 -D 数据库名



#在mysql配置文件 my.ini

#不允许插入空值

#sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

#允许插入空值

#sql-mode="NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"