ubuntu 安装 mysql 的正确姿势 mysql 1449 : The user specified as a definer ,'root'@'%' does not exist 解决方法

1、下载官方提供的mysql-apt-config.deb包进行APT源设置,下载地址:https://dev.mysql.com/downloads/repo/apt/

2、

// 将 mysql-apt-config_0.8.6-1_all.deb 上传到/opt/
// 执行以下命令
sudo dpkg -i mysql-apt-config_0.8.6-1_all.deb

3、 运行更新命令

sudo apt-get update

4、 安装

sudo apt-get install mysql-server

5、提示依赖不足时:

sudo apt-get install -f

6、

#服务启动后端口查询
sudo netstat -anp | grep mysql

7、

#服务管理
#启动
sudo service mysql start
#停止
sudo service mysql stop
#服务状态
sudo service mysql status

8、

#连接数据库
mysql -h 127.0.0.1 -P 3306 -uroot -p123456
#-h为远程IP,-P为端口号,-u为用户名,-p为密码

9、 show databases; 查看数据库

10、 卸载:

#首先使用以下命令删除MySQL服务器:
sudo apt-get remove mysql-server
#然后,删除随MySQL服务器自动安装的任何其他软件:
sudo apt-get autoremove
#卸载其他组件:
sudo apt-get remove <<package-name>>
#查看从MySQL APT存储库安装的软件包列表:
dpkg -l | grep mysql | grep ii

11 修改root密码

#修改root密码,每一个分号直接回车
mysql> SET PASSWORD = PASSWORD('新密码');
mysql> ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
mysql> flush privileges;
#增加一个'root'@'%'账号实现远程登录
CREATE USER 'root'@'%' IDENTIFIED BY 'Hadoop3!';
grant all privileges on *.* to 'root'@'%';
// 如果远程连接的时候报plugin caching_sha2_password could not be loaded这个错误,可以尝试修改密码加密插件
 mysql> alter user 'root'@'%' identified with mysql_native_password by 'Hadoop3!';
// 修改配置文件中的bind-address   文件路径:
vim /etc/mysql/mysql.conf.d/mysqld.cnf

将bind-address = 127.0.0.1 注释或者修改为bind-address = 0.0.0.0

重启mysql service

重置远程密码:

grant all privileges on *.* to dayu@"%" identified by "dayu1.net";

可能数据库没有此用户:

select user,host from mysql.user;

没找到此用户,但是报错出现了这个用户。寻求谷歌后,找到解决方法:

SELECT definer,type FROM mysql.proc GROUP BY definer,type;

UPDATE mysql.proc SET definer='root@localhost' WHERE definer = '报错的名称(root@%)';

重启数据库,OK