mysql

linux 安装mysql 8.0:

参考官方文档 : https://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/

1.添加mysql yum 存储库

下载mysql yum 存储库 :https://dev.mysql.com/downloads/repo/yum/

选择适合平台的软件发行包

安装下载的软件发型包 替换 platform-and-version-specific-package-name 为下载的RPM包的名称:

sudo yum localinstall platform-and-version-specific-package-name.rpm

image.jpeg
image.jpeg

2.安装mysql

通过以下命令安装mysql :

sudo yum install mysql-community-server

必须启动前配置:

/usr/sbin/mysqld --initialize --user=mysql --lower-case-table-names=1

3.启动mysql

启动 :

sudo service mysqld start

停止 :

sudo service mysqld stop

检测mysql 服务器的状态:

sudo service mysqld status

4.重置超级管理员密码

将'root'@'localhost创建一个超级用户帐户。设置超级用户的密码并将其存储在错误日志文件中。要显示它,请使用以下命令:

sudo grep 'temporary password' /var/log/mysqld.log

image.jpeg

用临时密码 登录 :

[图片上传中...(image-7efeae-1631951661092-0)]

更改密码策略 : 【生产环境不应该更改密码策略】

set global validate_password.policy=0; -- 修改密码策略 可以使用简单密码

set global validate_password.length = 4; -- 修改密码的最低长度是4

修改root密码 : 【注意 : 密码不能用root】

ALTER USER 'root'@'localhost' IDENTIFIED BY 'hyxxxxx';

5.安装后设置和测试

root账号设置远程连接可访问:

-- 切换mysql库

use mysql;

-- 更新域属性,'%'表示允许外部访问:

update user set host = "%" where user = "root";

-- 刷新权限

FLUSH PRIVILEGES;

-- 授权

GRANT ALL PRIVILEGES ON . TO 'root'@'%'WITH GRANT OPTION;

-- 解决navicat 登录不上问题

alter user 'root' identified with mysql_native_password by 'hy19940619';


1. show status like '%conn%'

Threads_connected 当前的连接数

max_connections MySQL设置的连接数。

Max_used_connections 服务器启动后已经同时使用的连接的最大数量。

Max_used_connections / max_connections * 100% = 3/512 *100% ≈ 0.0058%

服务器响应的最大连接数值占服务器上限连接数值的比例值在10%以上,

如果在10%以下,说明mysql服务器最大连接上限值设置过高.

2.show processlist 显示当前正在执行的mysql连接

show full processlist 显示完整sql

3.tps 查询 每秒事务数

select VARIABLE_VALUE into @num_com from GLOBAL_STATUS where VARIABLE_NAME ='COM_COMMIT';

select VARIABLE_VALUE into @num_roll from GLOBAL_STATUS

where VARIABLE_NAME ='COM_ROLLBACK';

select VARIABLE_VALUE into @uptime from GLOBAL_STATUS

where VARIABLE_NAME ='UPTIME';

select (@num_com+@num_roll)/@uptime;

4. QPS查询 每秒查询数

select VARIABLE_VALUE into @num_queries from GLOBAL_STATUS

where VARIABLE_NAME ='QUESTIONS';

select VARIABLE_VALUE into @uptime from GLOBAL_STATUS

where VARIABLE_NAME ='UPTIME';

select @num_queries/@uptime;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容