【walker 过程】
安装
sudo apt install mysql-server mysql-client
在 /etc/mysql/mysql.conf.d/mysqld.cnf 文件里面修改或添加
[mysqld] # 修改绑定ip bind-address = 0.0.0.0 # 设置最大内存 innodb_buffer_pool_size = 20G
重启 mysql 服务
sudo systemctl restart mysql.service
查看是否修改成功(数值的单位是 Bytes)
mysql -u root mysql> show variables like 'innodb_buffer_pool_size'; +-------------------------+-------------+ | Variable_name | Value | +-------------------------+-------------+ | innodb_buffer_pool_size | 21474836480 | +-------------------------+-------------+ 1 row in set (0.00 sec)
设置远程 root 访问
注意:update user set authentication_string=password('xxxx') where user='root'; 语句会与远程授权冲突。
mysql -u root
mysql> use mysql;
# authentication_string 以前叫 password
mysql> select user, host, authentication_string from user;
# 设置任意 ip 可使用 root 连接
mysql> update user set host='%' where user='root';
# xxxx 为远程访问密码
mysql> grant all privileges on *.* to 'root'@'%' identified by 'xxxx' with grant option;
# 刷新权限
mysql> flush privileges;
【修改字符集为 utf8/utf8mb4】
查看字符集
mysql> show variables like 'character_set_%';
mysql> show variables like 'collation_%';
合二为一:
SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation_%';
# OR
SHOW VARIABLES WHERE Variable_name REGEXP '^(character_set_|collation_).*';
在 /etc/mysql/mysql.conf.d/mysqld.cnf 文件里面修改或添加
[mysqld] # ... lc-messages-dir = /usr/share/mysql character-set-server = utf8mb4
在 /etc/mysql/conf.d/mysql.cnf 文件里面修改或添加
[client] default-character-set = utf8mb4 [mysql] default-character-set = utf8mb4
重启 mysql 服务
sudo systemctl restart mysql.service
再次查看
mysql -u root -p SHOW VARIABLES WHERE Variable_name REGEXP '^(character_set_|collation_).*';
【相关命令】
安全检查
sudo mysql_secure_installation
查看授权
show grants;
密码策略相关
# 查看密码策略
mysql> select @@validate_password_policy;
# 修改密码策略
mysql> set global validate_password_policy=0;
# 查看密码长度限制
mysql> select @@validate_password_length;
卸载 mysql 及配置文件
sudo apt remove --purge mysql-server mysql-client
【FAQ】
Q:导入数据报错 lost connection to MySQL server during query
A:可能原因是 max_allowed_packet 值过小。查询的方法:SHOW VARIABLES LIKE '%max_allowed_packet%';。可通过修改 /etc/mysql/mysql.conf.d/mysqld.cnf 里面的 max_allowed_packet 配置项调整。注意这个值并不需要比导入的 sql 文件大。当然也可能是网络问题(网卡、网线、交换机接口等)。
【相关阅读】
ubuntu18.04 安装mongodb并使用Robo 3T连接Mongodb数据库(作者写这篇文章的时候 mongodb bionic 版本尚未发布)
*** walker ***
转载于:https://blog.51cto.com/walkerqt/2114531