【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 ***