I’m participating in nuggets Creators Camp # 4, click here to learn more and learn together!

Just replaced my laptop system with the only Deepin Linux. I am happy to use it. Suddenly I want to use mysql. I arranged an APT install, but I did not change the password at the first time, so I could not enter the database later. After much thought, I finally set the password, so I would like to record this.

Environment of 0.

  • system

Deepin Linux 23 beta

  • Mariadb versions

Server version: 10.5.11- MariadB-1

Latest MariaDB Releases 10.8.2 (RC), 10.7.3 **, ** 10.6.7, 10.5.15, 10.4.24, 10.3.34, 10.2.43. Vote on your current version.

So mine is not the latest, of course very stable.

1. Install Mariadb with a command

sudo apt install mariadb-server
Copy the code

2. Enter Mariadb in password-free mode

sudo mariadb --defaults-file=/etc/mysql/debian.cnf
Copy the code

System prompt:

Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 31 Server version: 10.5.11-MariaDB-1 Debian 11 Copyright (C) 2000, 2018, Oracle, MariaDB Corporation Ab and Others. Type 'help; ' or '\h' for help. Type '\c' to clear the current input statement.Copy the code

3. Change the password

Password change command error:

MariaDB [mysql]> select user, host from user; +-------------+-----------+ | User | Host | +-------------+-----------+ | mariadb.sys | localhost | | mysql | localhost | | root | localhost | + -- -- -- -- -- -- -- -- -- -- -- -- - + -- -- -- -- -- -- -- -- -- -- - + 3 rows in the set (0.002 SEC) MariaDB/mysql > update user set Password=PASSWORD('root') where User='root' and Host='localhost'; ERROR 1356 (HY000): View 'mysql.user' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use themCopy the code

Root ‘@’localhost’ root’@’localhost’

MariaDB [mysql]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('root');
Query OK, 0 rows affected (0.005 sec)

Copy the code

The specific verification login is as follows:

(base) livingbody@livingbody-PC:~$ mysql -uroot -proot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 36 Server version: 10.5.11-MariaDB-1 Debian 11 Copyright (C) 2000, 2018, Oracle, MariaDB Corporation Ab and Others. Type 'help; ' or '\h' for help. Type '\c' to clear the current input statement.Copy the code

4. To summarize

The password is successfully changed because of the following two reasons:

  • 1. Privileged mode is enabled

/etc/mysql.debian.cnf file header: /etc/mysql.debian.cnf

# THIS FILE IS OBSOLETE. STOP USING IT IF POSSIBLE. # This file exists only for backwards compatibility for # tools that  run '--defaults-file=/etc/mysql/debian.cnf' # and have root level access to the local filesystem. # With those permissions one can run 'mariadb' directly # anyway thanks to unix socket authentication and hence # this file is useless. See package README for more info. [client] host = localhost user = root [mysql_upgrade] host = localhost user =  root socket=/var/run/mysqld/mysqld.sock # THIS FILE WILL BE REMOVED IN A FUTURE DEBIAN RELEASE.Copy the code
  • 2. Change the password

Mysql > alter table mysql > alter table mysql > alter table mysql > alter table mysql > alter table mysql > alter table mysql

Hope this article is useful to everyone, Good Luck!