1.删除mysql:
sudo apt-get remove mysql-*
然后清理残留的数据
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
它会跳出一个对话框,你选择yes就好了
2.安装mysql
sudo apt-get install mysql-client mysql-server
安装的时候会提示要设置root密码,如果你没有在卸载的时候去清理残留数据是不会提示你去设置root密码的
检查mysql是不是在运行
sudo service mysql status
一般安装完成之后都是会自动运行的。
如果没有运行你可以
sudo service mysql start
运行它
3.配置远程连接mysql
打开/etc/mysql/mysql.conf.d/mysql.cnf文件,将bind-address哪一行注释掉
1、在控制台执行
mysql -uroot -p
系统提示输入数据库root用户的密码,输入完成后即进入mysql控制台
2、选择数据库
use mysql;
开启远程连接
创建用户
create user wang identified by 'pws';
wang为用户名
下一步授予权限
%为人人都可访问
password 是密码
GRANT ALL PRIVILEGES ON *.* TO 'wang'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
刷新用户表
FLUSH PRIVILEGES;
重起mysql服务
service mysqld restart
如果执行完以上步骤,还是不能远程连接,那么我们需要查看服务器的防火墙是否开启
service iptables status
如果防火墙开启,请关闭
service iptables stop
到此就可以远程连接了!
还有两个常用操作;
修改指定用户密码
update mysql.user set authentication_string=password('新密码') where User="test" and Host="localhost";
删除用户
delete from user where User='test' and Host='localhost';
参考信息:
https://blog.csdn.net/sun614345456/article/details/53672150?utm_source=copy