記MySQL在Ubuntu(18.04.1 LTS)的安裝
阿新 • • 發佈:2018-12-18
本文記錄一次在Ubuntu(18.04.1 LTS)上安裝MySql過程,安裝後的mySQL版本為5.7.24。
安裝環境
[email protected]~virtual-machine:/etc# cat /etc/issue
Ubuntu 18.04.1 LTS
安裝mySql
以下為按照命令,在提示需要輸入 [Y/n] 時,輸入Y.
[email protected]~virtual-machine:~# sudo apt-get install mysql-server
[email protected]~virtual-machine:~# sudo apt-get install mysql-client
[email protected]~virtual-machine:~# sudo apt-get install libmysqlclient-dev
[email protected]~virtual-machine:~#
安裝完成後,進入mySql
[email protected]~virtual-machine:~# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.24-0ubuntu0.18.04.1 ( Ubuntu)
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
建立一個使用者並授權。
mysql> GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.03 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
修改mysqld.cnf配置並重啟MySQL服務
在安裝好後,需要修改MySQL配置,否則其他的資料電腦或虛擬機器不能連線該MySQL服務。在/etc/mysql/mysql.conf.d/mysqld.cnf裡面,注掉或者刪掉“bind-address = 127.0.0.1”,或者將“bind-address = 127.0.0.1修改為“bind-address = 0.0.0.0”。
[email protected]~virtual-machine:~# vi /etc/mysql/mysql.conf.d/mysqld.cnf
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
# bind-address = 127.0.0.1
當bind-address修改後,需要重啟mySQL服務。
[email protected]~virtual-machine:~# service mysql restart
通過Navicat 或者SQL Developer工具連線
在以上步驟完成後,可以通過Navicat或SQL Developer工具連線到已安裝的MySQL。此處使用SQL Developer連線到安裝的MySQL。
連線名(M):自己定義 使用者名稱(U):該值為前面建立的使用者user 口令(P):該值為前面建立的密碼password 主機名(A):主機名為MySQL安裝的地址 埠(R):埠為MySQL服務監聽埠