在 Ubuntu 18.04 中,默認狀況下,只有最新版本的 MySQL 包含在 APT 軟件包存儲庫中,要安裝它,只需更新服務器上的包索引並安裝默認包 apt-get。html
#命令1 sudo apt-get update #命令2 sudo apt-get install mysql-server
運行下面的命令配置mysql:mysql
sudo mysql_secure_installation
sudo netstat -tap | grep mysql
或者 sudo systemctl status mysql
sudo systemctl start mysql
sudo systemctl restart mysql
sudo systemctl stop mysql
啓動完成後在本機嘗試登錄一下,若是不能登陸。在執行下面的操做。sql
默認狀況下,mysql的root用戶只容許本機登陸。能夠經過下面的方式修改成遠程登陸。vim
修改配置文件mysqld.cnf,sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
,在 [mysqld] 下面加一行 skip-grant-tables
容許密碼是空字符串登陸。
而且註釋掉bind-address = 127.0.0.1
服務器
sudo mysql -u root -p
回車登陸。socket
use mysql select host,user,authentication_string,plugin,password_expired,password_last_changed from user;
mysql5.7如下版本: UPDATE mysql.user SET Password=PASSWORD('密碼') where USER='root'; mysql5.7版本: UPDATE mysql.user SET authentication_string=PASSWORD('密碼') where USER='root';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION; FLUSH PRIVILEGES;
skip-grant-tables
並重啓。sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
經過查詢 show variables like "%char%";
能夠看到character_set_server是拉丁編碼。修改sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
在[mysqld]下面加一行 character-set-server=utf8
。編碼
重啓mysql服務,再查詢show variables like "%char%";
能夠看到修改後的結果。.net
參考文檔: http://www.javashuo.com/article/p-dzqdcgyh-eu.html http://www.javashuo.com/article/p-eulqmzde-bu.html http://www.javashuo.com/article/p-uvihtaxp-co.html https://blog.csdn.net/qq_32786873/article/details/79225039rest