這篇文章要跟大家介紹Ubuntu18.04安裝MySQL的方法。有一定的參考價值,有需要的朋友可以參考一下,希望對大家有幫助。
環境資訊:
OS:Ubuntu18.04
MySQL: 5.7. 22
在Ubuntu
中,預設情況下,只有最新版本的MySQL
包含在APT
軟體包儲存庫中,要安裝它,只需更新伺服器上的包索引並安裝預設包apt-get
。
#命令1 sudo apt-get update #命令2 sudo apt-get install mysql-server
sudo mysql_secure_installation
設定項較多,如下所示:
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N (我的选项) #2 Please set the password for root here... New password: (输入密码) Re-enter new password: (重复输入) #3 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... Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的选项) #4 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 (我的选项) #5 By default, MySQL comes with a database named 'test' that anyone can access... Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的选项) #6 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 (我的选项)
systemctl status mysql.service
顯示以下結果說明mysql服務是正常的:
##3.設定遠端存取#在Ubuntu下MySQL缺省是只允許本地存取的,使用workbench連接工具是連不上的;如果你要其他機器也能夠存取的話,需要進行設定;3.1首先用根用戶進入sudo mysql -uroot -p
#
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";其中
root@localhos ,
localhost就是本地訪問,配置成
%就是所有主機都可連接;
'123456'為你給新增權限使用者設定的密碼,
%代表所有主機,也可以是具體的ip;
%但我root透過工具還是登陸不進去,可能是為了安全性,所以新建資料庫和使用者;
##1 创建数据库weixx CREATE DATABASE weixx; ##2 创建用户wxx(密码654321) 并允许wxx用户可以从任意机器上登入mysql的weixx数据库 GRANT ALL PRIVILEGES ON weixx.* TO wxx@"%" IDENTIFIED BY "654321";4.使用workbench連接資料庫開啟workbench進行連接配置: 配置完成後,在主介面選擇weixx資料庫進行連接: 相關推薦:《
mysql教學》
以上是Ubuntu18.04如何安裝MySQL的詳細內容。更多資訊請關注PHP中文網其他相關文章!