安装Mysql
注:以下的操作都是在root权限下
1. 更新系统(这是一个习惯,在安装软件时保证你的系统是最新的)
apt-get update
2. 安装mysql服务
apt-get install mysql-server
apt-get install mysql-client
apt-get install libmysqlclient-dev
3. 本地登录验证
mysql -u root -p
实现远程登陆
在远程访问数据库的时候你可能会遇见这样的情况:
解决方法如下:
1. 解除本地回旋地址的绑定
注释掉/etc/mysql/mysql.conf.d
文件中的bind-address = 127.0.0.1
2. 设置所有IP可以访问该数据库
# 本地登录mysql:
mysql -u root -p
# 打开mysql数据库
use mysql
#将host设置为%表示任何ip都能连接mysql,当然您也可以将host指定为某个ip
update user set host='%' where user='root' and host='localhost';
# 给root用户设置密码和授权
update user set authentication_string=password("你的密码") where user="root";
update user set authentication_string=password("你的密码"),plugin='mysql_native_password' where user='root';
#刷新权限表,使配置生效
flush privileges;
3. 配置阿里云的安全组
最后重启mysql服务
sudo service mysql restart
可能会使用到的命令
数据库操作:
#**关闭远程连接**
#打开mysql数据库
use mysql
#将host设置为localhost表示只能本地连接mysql
update user set host='localhost' where user='root';
#刷新权限表,使配置生效
flush privileges;
mysql服务操作
#启动
sudo service mysql start
#停止
sudo service mysql stop
#服务状态
sudo service mysql status
END!