Linux安装mysql(解决E: Package ‘mysql-server‘ has no installation candidate与ERROR 1698 (28000))

安装mysql

使用如下命令查询当前linux发行版的信息:

lsb_release -a
apt install mariadb-server mariadb-client

安装mariadb之后依旧是使用mysql命令,它是mysql的分支而已

配置root的密码

  1. sudo mysql_secure_installation
  2. 然后提示 Set root password? [Y/n],输入Y
  3. 然后输入两次mysql数据库的密码,此密码会被设置为mysql root的密码
  4. 然后一路回车即可

配置登录

这里通过配置解决ERROR 1698 (28000): Access denied for user ‘root’@'localhost’报错,详细参考:https://blog.csdn.net/jlu16/article/details/82809937

首先登陆:sudo mysql -u root
然后在mysql中输入:

USE mysql;
SELECT User, Host, plugin FROM mysql.user;

可以看到:

+------------------+---------------------------------+
| User             | plugin                          |
+------------------+---------------------------------+
| root             | auth_socket(或是unix_socket)   |
+------------------+---------------------------------+

此时输入:

UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;

然后在命令行中输入:

sudo service mysql restart

你可能感兴趣的:(运维,mysql)