Ubuntu安装
推荐使用apt
安装:
apt update && apt install mysql-server
默认root
可以免密登录:
mysql
通过systemctl
可以方便的控制启动和停止:
systamctl start mysql # 启动
systemctl stop mysql # 关闭
远程登录配置
默认只有本地能连接,如果要远程连接需要修改配置文件:/etc/mysql/my.cnf
# 添加下面内容
[mysqld]
bind-address = 0.0.0.0
创建用户
创建用户:
CREATE USER 'test' IDENTIFIED BY '123456'; # 默认所有地址都能登录【需要修改配置文件】
CREATE USER 'test'@'localhost' IDENTIFIED BY '123456'; # 只能本地登录
授予权限:
GRANT ALL PRIVILEGES ON *.* TO 'fxy'@'%'; # 授予所有的表
GRANT ALL PRIVILEGES ON *.* TO 'fxy'@'localhost'; # 授予所有的表
查看创建的用户:
SELECT User, Host FROM mysql.user;
删除用户:
drop user fxy;
修改密码:
ALTER USER 'username'@'host' IDENTIFIED BY 'new_password';
性能测试
安装sysbench
:
apt update && apt install sysbench
创建测试用的表:
sysbench oltp_read_write --mysql-user=test --mysql-password=123456 --mysql-db=test --tables=8 --threads=4 --table-size=1000000 prepare
开始测试:
sysbench oltp_read_write --mysql-user=test --mysql-password=123456 --mysql-db=test --tables=1 --threads=64 --report-interval=3 --time=30 run
删除测试用的表:
sysbench oltp_read_write --mysql-user=test --mysql-password=123456 --mysql-db=test --tables=64 cleanup