【walker 过程】html
安装mysql
sudo apt install mysql-server mysql-client
在 /etc/mysql/mysql.conf.d/mysqld.cnf 文件里面修改或添加sql
[mysqld] # 修改绑定ip bind-address = 0.0.0.0 # 设置最大内存 innodb_buffer_pool_size = 20G
重启 mysql 服务mongodb
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 访问ubuntu
注意: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】bash
查看字符集ionic
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 ***