How to install Mysql database on Debian 9 system, debianmysql
Preface
When you see the question, you should think about installing Mysql On Debian 9? Isn't that easy? Directsudo apt install mysql-server
Isn't that enough?
I did not expect to encounter a few problems that I had not encountered before, which delayed a lot of time.
In Debian 9, Mysql has been replaced with MariaDB, so it is different from the traditional Mysql installation.
Installation Method
First, we can usesudo apt install mysql-server
This method is installed, but MariaDB is installed, so it is best to usesudo apt install mariadb-server
That's it.
After the installation, it is found that it is different from the traditional one, because there is no blue interface for setting the password, And I mistakenly thought that I could directly log on with a blank password. Try directlymysql -uroot -p
, Found ERROR 1698 (28000): Access denied for user 'root'@'localhost'
. Isn't the default password blank? Check whether the default password in/etc/mysql/debian. cnf is null.
The first response is execution.mysqld_safe skip-grant-tables
, And thenuse mysql;
, And thenupdate user set password=PASSWORD('mysql') where User='root';
. This can solve the problem, but after the restart, you can find that you cannot log on again.
After a while, I found that the default password of MaraiDB is indeed empty, but I can only Log On As A Root user.
Note:Here the user is talking about the Root user of the linux system. That is to say, after you enter the Root terminal, sudo su can log on normally, but normal users cannot log on. (For the sake of distinction, I capitalized the first letter of the Root terminal, while the first letter of the root user of mysql was lowercase)
Probably understood, so we can't figure it to make it easy to keep using the root user. The correct posture should be like this:
First sudo apt install mariadb-server
Install the database.
Then switch sudo su to the Root terminal and runmariadb -uroot -p
Log on to the database. If the default password is not blank, you can view '/etc/mysql/debian. cnf '.
In this case, you need to create a new user:create user 'admin'@'localhost' identified by 'mysql'
.
Then set permissions for the new user:grant all on *.* to 'admin'@'localhost'
.
Now, we have set a convenient "Root" user, but changed the name to admin.
PS:I found that in the Root terminal, No matter what password is entered, the database can be normally connected... dizzy.
Summary
The above is all the content of this article. I hope the content of this article has some reference and learning value for everyone's learning or work. If you have any questions, please leave a message to us, thank you for your support.