以下为遇到mysql问题的一些解决记录
- 在debian下安装mysql8
目前,debian9的默认仓库里好像是mariadb,如果想安装mysql8.0的话,可以去官网下载tar包
或者deb包
安装。我是使用apt
软件源添加mysql
到debian仓库。以下教程在mysql官网都有,详细可以去官网查看。 - 下载mysql apt 配置包,我当前下载的版本为0.8.13-1,具体可以去官网查看
sudo weget https://repo.mysql.com//mysql-apt-config_0.8.13-1_all.deb
- 添加apt源
sudo dpkg -i xxxx_all.deb
解包安装你刚才下载的deb
包,安装成功后,进入apt
源目录可以看到mysql.list
文件
cd /etc/apt/sources.list.d
ls
- 更新软件源
sudo apt update
- 安装
mysql
sudo apt install mysql-server
tips
:安装过程中会要求选择版本和启用功能,关于密码加密规则,如果使用旧版navicat(12以下)
和phpmyadmin4.7
以下的请选择旧版(5.7)的加密规则,否则会导致连接失败。
- 安装后问题之无法远程连接
对于想要远程访问服务器数据库的话,需要开启远程连接,mysql默认关闭。
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17 MySQL Community Server - GPL
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> quit;
service mysql restart;
不建议开启root的远程连接权限,我只是演示,你应当建立一个新用户,赋予权限后开启远程连接。下面是额外操作
#允许所有用户远程访问 修改用户名和密码为你自己的
mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'%' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
#允许单个ip 修改用户名和密码为你自己的
mysql> GRANT ALL PRIVILEGES ON *.* TO 'USERNAME'@'1.2.3.4' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;
#最后
mysql> flush privileges;
- 安装后问题之更改密码加密规则
mysql 8.0
修改了加密的插件方式,导致很多旧版本的navicat
无法正常访问,好像phpmyadmin4.7
以下也一样,我尝试过一次。
mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'xxxxxxxx';
Query OK, 0 rows affected (0.06 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)
这是通过ip
访问的修改方式,如果是本地访问的话,记得修改localhost
。