首先查看一下自己PC是否安装了其他版本的mysql,有则删之。。。
查看版本号:
mysql -V
apt-get autoremove --purge mysql-server-版本号
apt-get autoremove mysql-server
apt-get remove mysql-common
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
至此,卸载完成。。。
接下来就是安装了~~~
注:本人使用命令安装简单方便,官网下载压缩包安装也可以,比较繁琐。。。
sudo apt-get install mysql-server mysql-client
一路安装下来并没有发现设置密码,接下来设置密码。。。天坑(⊙﹏⊙)
注:之前设置密码参考了网上好多资料,跳进了好多坑,皇天不负苦心人。(⊙﹏⊙)
cat /etc/mysql/debian.cnf
记下其中的user和password字段内容
mysql -u user字段内容 -p
输入password字段内容,以debian的配置登入mysql
mysql> use mysql;
mysql> select host,user,plugin,authentication_string from user;
注:root用户的plugin为auth_socket,密码为空
mysql> update user set plugin="mysql_native_password",authentication_string=password('新密码') where user="root";
mysql> FLUSH PRIVILEGES;
5.mysql -u root -p并以新密码登入mysql;
MySQL 使用 show tables 时出现 ERROR 1449 (HY000) 问题
问题出现
在安装完 MySQL 后,使用 SHOW TABLES 时,发现一直出现 ERROR 1449 (HY000):The user specified as a definer (‘mysql.infoschema‘@’localhost’) does not exist 。具体去网上搜索,给的答案都是用 mysql_upgrade ,事实上 mysql_upgrade 功能在 mysql8.0 之后版本已经停用了。在经过多方查找后,找到如下解决方案。
mysql> use goblog
Database changed
mysql> show tables;
ERROR 1449 (HY000): The user specified as a definer ('mysql.infoschema'@'localhost') does not exist
解决方案
总体办法就是给 mysql.infoschema 用户添加权限。
MySQL8.0 之后,不支持使用 grant 时隐式地创建用户,必须先创建用户,再授权。代码如下:
mysql> create user 'mysql.infoschema'@'%' identified by '密码';
Query OK, 0 rows affected (0.01 sec)
mysql> create user 'mysql.infoschema'@'%' identified by '密码';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on *.* to 'mysql.infoschema'@'%';
Query OK, 0 rows affected (0.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)
再使用 show tables ,就能出现结果了。
mysql> show tables;
+------------------+
| Tables_in_goblog |
+------------------+
| articles |
+------------------+
1 row in set (0.01 sec)