在 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