在Linux中安装使用MariaDB,在首次启动MariaDB后,出现了无法将其初始化设置、不能设置root用户登入密码、不能创建新用户登入问题。
输入 mysql_secure_installation
进行初始化设置,但却提示 ERROR 1698 (28000): Access denied for user 'root'@'localhost'
。
[black@localhost ~]$ mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):
进入MariaDB后,无论是设置root密码,还是创建用户,都是提示 ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
。
[black@localhost ~]$ mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 24
Server version: 10.4.10-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD('qwer1234');
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
MariaDB [(none)]> CREATE USER 'test_database'@'localhost' IDENTIFIED BY '123456';
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
MariaDB [(none)]>
解决该问题的方法是使用root用户进行操作。
[black@localhost ~]$ sudo mysql_secure_installation
Enter current password for root (enter for none):
#初次运行直接回车
Set root password? [Y/n]
#是否设置root用户密码,输入y并回车或直接回车
New password:
#设置root用户的密码
Re-enter new password:
#再输入一次设置root用户密码
Remove anonymous users? [Y/n]
#是否删除匿名用户
Disallow root login remotely? [Y/n]
#是否禁止root远程登录
Remove test database and access to it? [Y/n]
#是否删除测试数据库
Reload privilege tables now? [Y/n]
#是否重新加载权限表
最后再重启一下MariaDB就可以了。
[black@localhost ~]$ systemctl restart mysql
文章评论