安裝
sudoaptinstallmysql-server mysql-client
在?/etc/mysql/mysql.conf.d/mysqld.cnf 文件里面修改或添加
[mysqld]# 修改綁定ipbind-address=0.0.0.0# 設(shè)置最大內(nèi)存innodb_buffer_pool_size=20G
重啟 mysql 服務(wù)
sudosystemctl restart mysql.service
查看是否修改成功(數(shù)值的單位是 Bytes)
mysql -u rootmysql>show variables like'innodb_buffer_pool_size';+-------------------------+-------------+|Variable_name|Value|+-------------------------+-------------+|innodb_buffer_pool_size|21474836480|+-------------------------+-------------+1 rowinset(0.00 sec)
設(shè)置遠(yuǎn)程 root 訪(fǎng)問(wèn)
注意:update user set authentication_string=password('xxxx') where user='root';語(yǔ)句會(huì)與遠(yuǎn)程授權(quán)沖突谚攒。
mysql-u rootmysql>usemysql;# authentication_string 以前叫 passwordmysql>selectuser,host,authentication_stringfromuser;# 設(shè)置任意 ip 可使用 root 連接mysql>updateusersethost='%'whereuser='root';# xxxx 為遠(yuǎn)程訪(fǎng)問(wèn)密碼mysql>grantallprivilegeson*.*to'root'@'%' identified by 'xxxx'withgrantoption;# 刷新權(quán)限mysql>flushprivileges;
【修改字符集為 utf8/utf8mb4】
參考:Ubuntu中MySQL5.7設(shè)置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 服務(wù)
sudosystemctl restart mysql.service
再次查看
mysql -u root -pSHOW VARIABLES WHERE Variable_name REGEXP'^(character_set_|collation_).*';
【相關(guān)命令】
安全檢查
sudomysql_secure_installation
查看授權(quán)
showgrants;
密碼策略相關(guān)
# 查看密碼策略mysql>select@@validate_password_policy;# 修改密碼策略mysql>setglobalvalidate_password_policy=0;# 查看密碼長(zhǎng)度限制mysql>select@@validate_password_length;
卸載 mysql 及配置文件
sudoapt remove --purge mysql-server mysql-client
【FAQ】
Q:導(dǎo)入數(shù)據(jù)報(bào)錯(cuò)lost connection to MySQL server during query?
A:可能原因是?max_allowed_packet 值過(guò)小标捺。查詢(xún)的方法:SHOW VARIABLES LIKE '%max_allowed_packet%';植旧。可通過(guò)修改?/etc/mysql/mysql.conf.d/mysqld.cnf 里面的? max_allowed_packet 配置項(xiàng)調(diào)整扁凛。注意這個(gè)值并不需要比導(dǎo)入的 sql 文件大。當(dāng)然也可能是網(wǎng)絡(luò)問(wèn)題(網(wǎng)卡闯传、網(wǎng)線(xiàn)谨朝、交換機(jī)接口等)。
【相關(guān)閱讀】
MySQL 5.7 安裝完成后甥绿,立即要調(diào)整的性能選項(xiàng)
MySQL 安全檢查:MySQL安全配置向?qū)ysql_secure_installation
Ubuntu Server 18.04 切換軟件源到國(guó)內(nèi)鏡像
ubuntu18.04 安裝mongodb并使用Robo 3T連接Mongodb數(shù)據(jù)庫(kù)(作者寫(xiě)這篇文章的時(shí)候 mongodb bionic 版本尚未發(fā)布)
***walker***