每次安装mysql都要百度, 自己记录下
- 安装
apt-get update
apt-get install mysql-server
注意: 安装过程中, 需要设置mysql的登录密码, 不要一直按回车,耐心设置密码并牢记, 之后登录会使用
安装成功后使用一下命令检查是否安装成功
systemctl status mysql .service
输出: root@localhost:/etc/mysql/mysql.conf.d# systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
标识已经成功安装并启动
若没有启动, 使用 systemctl mysql start 将mysql启动
之后就可以愉快的 mysql -u root -p 使用mysql了
- 远程连接
登录mysql
mysql -u root -p
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| localhost | root |
| localhost | debian-sys-maint |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql>
授权
将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%
update user set host = ’%’ where user = ’root’;
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| localhost | debian-sys-maint |
| localhost | mysql.session |
| localhost | mysql.sys |
+-----------+------------------+
4 rows in set (0.00 sec)
mysql>
完成, 可以通过Navicat等软件进行远程连接
- 其他
1. 远程连接有时会连接很慢或直接报错(ERROR 2013 (HY000): Lost connection to MySQL server)
具体原因应该是, 反向解析ip导致time out....................
解决办法:
cd /etc/mysql/mysql.conf.d/
vi mysqld.cnf
在[mysqld] 段增加一个启动参数: skip-name-resolve