在使用命令行 sudo apt-get upgrade时,出现更新MySQL的问题
查询很多方法后,无奈选择重装MySQL
将MySQL重装的操作步骤记录方便下次再次遇到问题时处理。
卸载MySQL
(卸载时数据库数据会被一并删除,记得备份!!)
删除mysql的数据文件
sudo rm /var/lib/mysql/ -R
删除mysql的配置文件
sudo rm /etc/mysql/ -R
自动卸载mysql(包括server和client)
sudo apt-get autoremove mysql* --purge
sudo apt-get remove apparmor
然后在终端中查看MySQL的依赖项
dpkg --list|grep mysql
这里为空就说明卸载完成了。
安装MySQL
安装
sudo apt-get update
sudo apt-get install mysql-server
sudo apt-get install mysql-client
sudo apt-get install libmysqlclient-dev
配置
vi /etc/mysql/my.cnf
也可能是/etc/mysql/mysql.conf.d/mysqld.cnf
里面要包含[mysqld]的配置
在[mysqld] 添加以下项
character_set_server=utf8
skip-name-resolve
skip-external-locking
打开配置文件(my.cnf),找到这行
bind-address = 127.0.0.1
前边加#注释掉
重置密码
[mysqld]下添加
skip-grant-tables
(安装MySQL时有时会生成默认密码,添加这句为了进入mysql直接更改密码,修改密码之后注释掉)
修改密码
show databases;
use mysql;
select plugin from user where user = 'root';
update user set plugin='mysql_native_password';
update user set authentication_string=password('123456') where user='root' and host='localhost';
flush privileges;
quit;
新建用户赋权限
进入mysql
mysql -p -u root
然后在mysql中执行
MySQL>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'yourpassword' WITH GRANT OPTION;
MySQL>FLUSH PRIVILEGES;
回去之前配置文件
将skip-grant-tables前加#注释
然后重启MySQL
service mysql restart
防火墙添加端口
sudo iptables -A INPUT -p tcp --dport 3306 -j ACCEPT
如果出现mysql没法连接Qt的问题