安装MySQL
首先获得root权限, 然后安装
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
然后,设置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.
注意
*.*:第一个*代表数据库名;第二个*代表表名。这里的意思是所有数据库里的所有表都授权给用户。root:授予root账号。“%”:表示授权的用户IP可以指定,这里代表任意的IP地址都能访问MySQL数据库。“password”:分配账号对应的密码,这里密码自己替换成你的 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
出现错误, 删除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.