如何修改密码及授权
> systemctl start mysqld.service
> grep "password" /var/log/mysqld.log
> mysql -u root -p
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> alter user 'root'@'localhost' IDENTIFIED BY 'password';
mysql> grant all privileges on *.* to root@'%' identified by 'password';
mysql> flush privileges;
> vi /etc/my.cnf
skip-grant-tables
> systemctl restart mysqld.service
> mysql -uroot -p
mysql> use mysql;
mysql> update user set authentication_string = password("password") where user="root";
mysql> flush privileges;
字符串比较时发生错误问题
java.sql.SQLException: Illegal mix of collations (utf8_esperanto_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=';
show create table <表名>;
alter table <表名> character set utf8 COLLATE utf8_general_ci;
show full columns from <表名>;
select charset(<字段名>) from<表名>;
alter table <表名> modify <字段名> <字段类型> character set utf8 collate utf8_general_ci;
使用多个join(select)表连接合并,执行速度缓慢问题
show global variables like '%switch%';
set session optimizer_switch = 'derived_merge=off';
set global optimizer_switch = 'derived_merge=off';
进程等待、死锁问题
show processlist;
select * from information_schema.innodb_trx order by trx_started asc;
show open tables where in_use > 0;
kill id;
删除大量数据操作耗时较长问题
create table '备份表名' select * from '表名' where 1 != 1;
insert into '备份表名' select * from '表名' where time > '日期';
truncate table '表名' drop storage;
set foreign_key_checks = 0;
insert into '表名' select * from '备份表名';
数据删除后,长度空间不变问题
show table status like 'table_name'
optimize table table_name