Ubuntu Server 18.04 与 MySQL 5.7

安装

sudoaptinstallmysql-server mysql-client

在 /etc/mysql/mysql.conf.d/mysqld.cnf 文件里面修改或添加

[mysqld]# 修改绑定ipbind-address=0.0.0.0# 设置最大内存innodb_buffer_pool_size=20G

重启 mysql 服务

sudosystemctl restart mysql.service

查看是否修改成功(数值的单位是 Bytes)

mysql -u rootmysql>show variables like'innodb_buffer_pool_size';+-------------------------+-------------+|Variable_name|Value|+-------------------------+-------------+|innodb_buffer_pool_size|21474836480|+-------------------------+-------------+1 rowinset(0.00 sec)

设置远程 root 访问

注意:update user set authentication_string=password('xxxx') where user='root';语句会与远程授权冲突。

mysql-u rootmysql>usemysql;# authentication_string 以前叫 passwordmysql>selectuser,host,authentication_stringfromuser;# 设置任意 ip 可使用 root 连接mysql>updateusersethost='%'whereuser='root';# xxxx 为远程访问密码mysql>grantallprivilegeson*.*to'root'@'%' identified by 'xxxx'withgrantoption;# 刷新权限mysql>flushprivileges;

【修改字符集为 utf8/utf8mb4】

参考:Ubuntu中MySQL5.7设置utf8编码格式步骤

查看字符集

mysql>showvariableslike'character_set_%';mysql>showvariableslike'collation_%';

合二为一:

SHOWVARIABLESWHEREVariable_nameLIKE'character_set_%'ORVariable_nameLIKE'collation_%';# ORSHOWVARIABLESWHEREVariable_nameREGEXP'^(character_set_|collation_).*';

在 /etc/mysql/mysql.conf.d/mysqld.cnf 文件里面修改或添加

[mysqld]# ...lc-messages-dir=/usr/share/mysqlcharacter-set-server=utf8mb4

在 /etc/mysql/conf.d/mysql.cnf 文件里面修改或添加

[client]default-character-set=utf8mb4[mysql]default-character-set=utf8mb4

重启 mysql 服务

sudosystemctl restart mysql.service

再次查看

mysql -u root -pSHOW VARIABLES WHERE Variable_name REGEXP'^(character_set_|collation_).*';

【相关命令】

安全检查

sudomysql_secure_installation

查看授权

showgrants;

密码策略相关

# 查看密码策略mysql>select@@validate_password_policy;# 修改密码策略mysql>setglobalvalidate_password_policy=0;# 查看密码长度限制mysql>select@@validate_password_length;

卸载 mysql 及配置文件

sudoapt 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 文件大。当然也可能是网络问题(网卡、网线、交换机接口等)。

【相关阅读】

MySQL 5.7 安装完成后,立即要调整的性能选项

MySQL 安全检查:MySQL安全配置向导mysql_secure_installation

Ubuntu Server 18.04 切换软件源到国内镜像

ubuntu18.04 安装mongodb并使用Robo 3T连接Mongodb数据库(作者写这篇文章的时候 mongodb bionic 版本尚未发布)

***walker***

你可能感兴趣的:(Ubuntu Server 18.04 与 MySQL 5.7)