例:收集日志文件、服务器状态信息 查看日志是否开启,以及位置 show variables like "%log_error%"; show variables like "slow_query_log"; show variables like "long_query_log"; show variables like "long_query_time"; show variables like "%log_bin%"; show variables like "%general%"; show variables like "%relay%";
查看数据库状态 show variables like 'version'; show databases; status show status; show engines; show plugins; show engine innodb status; show processlist; show variables like 'collation%'; show collation like '%utf8%'; show master status; show slave status;
mv mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz /usr/local/ cd /usr/local/ tar -xf mysql-5.7.44-linux-glibc2.12-x86_64.tar.gz mv mysql-5.7.44-linux-glibc2.12-x86_64 mysql mkdir /usr/local/mysql/data mkdir /usr/local/mysql/logs useradd mysql
数据库初始化操作; #第一次修改root密码 set password=password("Admin@123!");
#修改root密码 mysql -u root -p use mysql; update user set authentication_string=password("Admin@123!")where user="root"; flush privileges; exit;
#允许root远程登录 mysql -u root -p use mysql; select host,user from user where user='root'; grant all privileges on *.* to 'root'@'%' identified by 'Admin@123!' with grant option; flush privileges; exit;
mysql -u root -p #创建数据库 create database wsdb DEFAULT CHARSET utf8; #创建新用户 CREATE USER 'wangsheng'@'%' IDENTIFIED BY 'wangsheng'; #查看所有用户 SELECT HOST,USER FROM mysql.user; #给新用户分配权限(所有主机都可以访问) grant all privileges on wsdb.* to 'wangsheng'@'%'; #给新用户分配权限(仅本地可以访问) grant all privileges on wsdb.* to 'wangsheng'@'localhost';
#创建表 use wsdb; create table ws01( -> id int auto_increment primary key, -> name varchar(15) -> )engine=InnoDB;
#插入数据 INSERT INTO ws01 VALUES (1,'xhy01'); INSERT INTO ws01 VALUES (2,'xhy02'); INSERT INTO ws01 VALUES (3,'xhy03'); commit;
#查询数据 select * from wsdb.ws01; +----+-------+ | id | name | +----+-------+ | 1 | xhy01 | | 2 | xhy02 | | 3 | xhy03 | +----+-------+
use wsdb; select * from ws01; +----+-------+ | id | name | +----+-------+ | 1 | xhy01 | | 2 | xhy02 | | 3 | xhy03 | +----+-------+
groupadd mysql useradd -r -g mysql -s /bin/false mysql wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz tar -xf mysql-8.0.15-linux-glibc2.12-x86_64.tar.xz mv mysql-8.0.15-linux-glibc2.12-x86_64 mysql mv mysql /usr/local/ mkdir /usr/local/mysql/logs -p mkdir /usr/local/mysql/data -p chown -R mysql:mysql /usr/local/mysql
vim ~/.bash_profile PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
排查方式 1.查看系统状态top iostat等 2.查看mysql连接数与sql语句 show processlist 3.查看innodb状态show engine innodb status 4.查看状态show global status 5.看慢日志,分析sql与优化sql 6.查看错误日志
show variables like '%log_error%'; show variables like '%log_bin%'; show variables like '%slow_query_log%'; show variables like '%log_query_time%'; show variables like '%general%'; show variables like '%relay%'; show variables like 'version'; sow databases; status; show status; show engines; show plugins; show engine innodb status; show processlist; show variables like 'charact'; show variables like 'collation%'; show master status; show slave status;
mysqltuner-perl性能优化建议者 [major/MySQLTuner-perl: MySQLTuner is a script written in Perl that will assist you with your MySQL configuration and make recommendations for increased performance and stability. (github.com)](https://github.com/major/MySQLTuner-perl)