mysql -h 127.0.0.1 -u root -p
select version();
show variables like 'port';
show variables like 'datadir';
exit; 或 quit;
select host, user from mysql.user;
create user {username} identified by {password};
授予全部权限
grant all privileges on *.* to moyou@'%';
授予部分权限
grant select on *.* to moyou@'%';
例: grant select on nkbdp.* to finance@'%'; --授予finance用户在nkbdp库的查询权限
grant create on finance.* to finance@'%'; --授予finance用户在nkbdp库的建表权限
如果加上 with grant option则表示用户有权限赋予其他用户权限
例:
grant all privileges on *.* to moyou@'%' with grant option;
grant select on nkbdp.* to finance@'%' with grant option;
刷新权限
flush privileges;
alter user 'root'@'localhost' identified by '新密码';
或
update mysql.user set authentication_string=password('新密码') where user='用户名' and Host ='localhost';
show variables like 'validate_password%';
或
show plugins;
install plugin validate_password soname 'validate_password.dll';
show variables like 'validate_password%';
validate_password_dictionary_file --字典文件
validate_password_length --密码最小长度
validate_password_mixed_case_count --大写字母最少数量
validate_password_number_count --数字最少数量
validate_password_policy --密码等级
validate_password_special_char_count --最少包含特殊字符数量
注:MySQL 5.6.35及之后的版本才会有connection_control插件
查看是否安装控制插件
show variables like '%connection_control%';
或
show plugins;
安装插件
install plugin connection_control soname “connection_control.dll”;
报错以下错误,说明没有该插件
ERROR 1126 (HY000): Can’t open shared library ‘C:\Program Files\MySQL\MySQL Serv
er 5.6\lib\plugin\connection_control.so’ (errno: 126 \00D5\04B2\00BB\00B5\00BD\0
5B8\00B6¨\00B5\00C4\0123\00BF)
show variables like '%ssl%';
\s
显示SSL: Not in use 说明连接没有在SSL安全连接中。
select
concat('ALTER TABLE ', table_name, ' DROP FOREIGN KEY ', CONSTRAINT_NAME, ';') as dropFk,
concat('ALTER TABLE ', table_name, ' DROP INDEX ', CONSTRAINT_NAME, ', ADD INDEX ', UPPER(column_name), '_INDEX(', column_name,') USING BTREE;') as changeIndex
from information_schema.KEY_COLUMN_USAGE
where TABLE_SCHEMA = 'land_rent'
-- and table_name like 'gt_td_encroach_recovery'
and CONSTRAINT_NAME like 'fk%'
-- ORDER BY REFERENCED_TABLE_NAME
ORDER BY TABLE_NAME
;
随着业务的增长,数据会越来越多,系统盘空间会爆满,这时就需要迁移数据文件到其他磁盘中。
mkdir /usr/local/mysql
mkdir /usr/local/mysql/data
mkdir /usr/local/mysql/log
因为如果目录的主属不是mysql用户,mysql是无法访问的
chown -R mysql.mysql /usr/local/mysql
mv /var/lib/mysql/* /usr/local/mysql/data # 数据文件
mv /var/log/mysqld.log /usr/local/mysql/log # 日志文件
linux 默认配置文件为/etc/my.cnf