一、安装MySQL
sudo apt-get install mysql-server
如果出现问题运行
sudo apt-get update
然后再运行第一句
二、修改数据库密码
登录MySQL mysql -u root -p 你的原密码
update mysql.user set authentication_string=password('你的密码') where user='root'
如果是忘记密码:
1.
service mysql stop
2.
mysqld_safe --skip-grant-tables --skip-networking
3.然后在登录mysql执行上面修改数据库密码的命令
update mysql.user set authentication_string=password('你的密码') where user='root'
4.退出MySQL
exit
5.更改完密码记得重启MySQL
service mysql restart
三、MySQL设置远程登录
1、登录mysql
mysql -u root -p 你的密码
2、设置root用户拥有远程访问权限
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码' WITH GRANT OPTION;
3、刷新更改
flush privileges;
4、退出数据库
exit
5、由于MySQL默认支持本地使用,所以需要到配置文件中注释掉绑定的本地连接
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
6、注释掉其中的"
#bind-address = 127.0.0.1
7、保存修改退出配置文件
control+x 后 y 后 enter
8、重启MySQL
service mysql restart
9、完成,可以在远程客户端登录MySQL数据库了!注意:如果是登录阿里云上的Linux的MySQL需要设置安全组,将3306端口添加进去!
1.点击云服务器ECS
2.点击配置规则
3.添加安全组规则
4.设置成如下就可以通过本地客户端直接连接Linux服务器中的MySQL数据库了