Deepin安装MySQL(MariaDB)不提示设置密码问题(密码为空)


@Deepin安装MySQL(MariaDB)不提示设置密码问题(密码为空)

1、安装Mysql

输入命令:

# sudo apt-get update
# sudo apt-get install mysql-server mysql-client

发现没有提示设置密码,按照教程在/etc/mysql/下找到debian.conf文件获取用户名和密码 ,发现密码为空,输入不了,无法登陆。

# sudo cat /etc/mysql/debian.cnf
# mysql -uroot -p
Enter password: 

2、修改密码

准备修改密码,按照以下文章尝试;
如何修改mysql数据库密码/如何处理debian-sys-maint密码被修改的情况.

# sudo service mysql stop
# sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking

然后另开一个终端,登入数据库,更新密码

# mysql
MariaDB [(none)]> use mysql;
MariaDB [mysql]> update user set password=password('123456') where user='root'
MariaDB [mysql]> flush privileges; 

依然无法登录。

3、进行MariaDB的安全设置

# mysql -V
mysql  Ver 15.1 Distrib 10.1.37-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

通过版本查看,发现MySQL更替为了MariaDB。MariaDB默认root密码为空,所以进行设置:

# sudo systemctl start mariadb
# sudo /usr/bin/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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Sorry, you can't use an empty password here.

New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

原文章: mysql(mariadb)重装.
然而还是没什么卵用。

4、卸载重装

重复尝试多次后,切换到root,卸载MySQL,然后重装,竟然好了/(ㄒoㄒ)/~~

$ su root
# apt-get remove --purge mysql-\*  
# apt-get autoremove mysql-server
# apt-get remove mysql-common
# dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
# apt-get install mysql-server mysql-client

重装之后,密码还是空,但是能登录。

# pgrep mysqld
8957
# mysql -uroot -p
Enter password: 
elcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.37-MariaDB-0+deb9u1 Debian 9.6

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

5、(更新)最终解决办法

最终查明原因是用户插件问题。按照第二步方法更改密码的方式,增加插件说明:

MariaDB [(none)]> UPDATE mysql.user SET authentication_string = PASSWORD('mypassword'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> exit

关闭,重启服务:

$ service mysql stop
$ sudo service mysql start
  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值