安裝MySQL
首先獲得root權(quán)限, 然后安裝
apt install mysql-server
apt isntall mysql-client
apt install libmysqlclient-dev
檢測是否安裝成功
netstat -tap | grep mysql
#顯示
tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN 6927/mysqld
遠程連接MySQL
首先, 注釋掉 /etc/mysql/mysql.conf.d/mysqld.cnf 中的 bind-address = 127.0.0.1
然后,設(shè)置mysql的賬戶和密碼
> mysql -uroot -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
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.
注意
*.*:第一個*代表數(shù)據(jù)庫名;第二個*代表表名。這里的意思是所有數(shù)據(jù)庫里的所有表都授權(quán)給用戶。root:授予root賬號。“%”:表示授權(quán)的用戶IP可以指定,這里代表任意的IP地址都能訪問MySQL數(shù)據(jù)庫?!皃assword”:分配賬號對應(yīng)的密碼,這里密碼自己替換成你的 mysql root帳號 密碼。
mysql> grant all on *.* to root@'%' identified by 'root' with grand option;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'grand option' at line 1
出現(xiàn)錯誤, 刪除grand option就行了.
mysql> GRANT ALL ON *.* TO root@'%' IDENTIFIED BY 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
刷新操作
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
重啟MySQL
> /etc/init.d/mysql restart
[ ok ] Restarting mysql (via systemctl): mysql.service.