Ubuntu平臺(tái)安裝
-
MySQL
的軟件包在Ubuntu
默認(rèn)軟件倉(cāng)庫(kù)中可用茶宵,默認(rèn)的版本號(hào)為5.7.27
,可通過(guò)以下命令安裝:yjf@vbox:~$ sudo apt update yjf@vbox:~$ sudo apt install mysql-server
-
運(yùn)行
mysql_secure_installation
命令進(jìn)行MySQL
以下六步配置。yjf@vbox-ubuntu:~$ sudo mysql_secure_installation `` Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: n #1 配置是否需要密碼插件 選擇n Please set the password for root here. New password: Re-enter new password: #2 為root用戶(hù)配置密碼 By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y #3 移除匿名用戶(hù) Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y #4 配置root不允許遠(yuǎn)程訪問(wèn) Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y #5 移除測(cè)試數(shù)據(jù)庫(kù) Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y #6 重新加載權(quán)限表 Success. All done!
- 運(yùn)行`sudo service mysql status`檢查`MySQL`服務(wù)是否啟動(dòng)成功辟宗。
- 配置遠(yuǎn)程訪問(wèn)用戶(hù)
```bash
yjf@vbox:~$ sudo mysql -uroot -p #需本機(jī)登錄且輸入上面配置的密碼
Enter password:
mysql> CREATE USER yjf IDENTIFIED BY 'yjf'; #新建用戶(hù)yjf 密碼為yjf
mysql> GRANT ALL PRIVILEGES ON *.* TO 'yjf'@'%' IDENTIFIED BY 'yjf' WITH GRANT OPTION; #f授權(quán)用戶(hù)yjf
mysql> FLUSH PRIVILEGES;
-
解決遠(yuǎn)程訪問(wèn)問(wèn)題和亂碼問(wèn)題。
#1 修改/etc/mysql/mysql.conf.d/mysqld.cnf文件, 如下 # bind-address = 127.0.0.1 增加注釋 # 在[mysqld]下增加以下兩行配置 character_set_server=utf8 init_connect='SET NAMES utf8'
-
重啟
mysql
服務(wù),常用的命令如下:# sudo service mysql restart //重啟 # sudo service mysql start //啟動(dòng)mysql服務(wù) # sudo service mysql status //查看MySQL的啟動(dòng)狀態(tài),下圖顯示正常啟動(dòng). # sudo service mysql stop //停止mysql服務(wù) #常用的mysql默認(rèn)配置文件位置 # 配置文件:/etc/my.cnf # 日志文件:/var/log//var/log/mysqld.log # 服務(wù)啟動(dòng)腳本:/usr/lib/systemd/system/mysqld.service # socket文件:/var/run/mysqld/mysqld.pid