Deploying MySQL/ under Linux system and reporting error ERROR 1045 (28000): Access denied for user root@localhost (using password:


Brief question: When we learn to build a data warehouse management environment, we need to learn how to deploy and use MySQL under Linux, and master the application of MySQL under different operating systems.

Steps:

1. Install mysql

1. Replace the default metadata database of hive with mysql The metadata database derby used is replaced with mysql (after derby is turned on, it will occupy the metadata database and does not share data with other clients, so it is replaced with mysql)
(1) View the default installed mysql version

rpm -qa | grep mariadb

(2) Uninstall

rpm -e –nodeps mariadb-libs

2. Upload and decompress
(1) Upload compressed package

Use the rz -E command

(2) Decompress the compressed package

tar -xf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar -C /opt/modules

(3)rpm installation software package

rpm -ivh

rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm

Note: There are also some disadvantages when using rpm to install software packages:

1. Compilation, installation, configuration, and deployment are relatively complicated.

2. Dependencies between software packages cannot be automatically resolved.

3. Because the installation package is too new, or the version is too low, or other problems, the dependent package is not available, so the package dependency problem must be solved.

3. Tool software download

#Download the following software
yum install -y perl-Module-Install.noarch
yum clean all
yum makecache
#Install net-tools
yum -y install net-tools
#Install again and that’s it

4. Delete the original mysql log data

cd /var/lib/mysql & amp; & rm -rf ./*

5. Initialization data

Initialization refers to assigning an initial value to a data object or variable.

mysqld –initialize –user=mysql

(2).mysql basic configuration

1. View the root password temporarily generated by the mysql database

cat /var/log/mysqld.log

This is the password we temporarily generated: & amp;(xwq5lxofeQ

Don’t think it looks complicated, we will turn it into a simple password later

2. Modify configuration file

vi /etc/my.conf

init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
3. Start mysql service

systemctl start mysqld

4. Use the temporarily generated password to log in to the mysql database

mysql -u root -p

The password is the password we just generated: & amp;(xwq5lxofeQ

5. Modify the login password and authorize remote login

Change the temporary password &(xwq5lxofeQ to 123456

set password = password(“123456”);

update mysql.user set host=’%’ where user=’root’;

flush privileges;

correct version

Extension: The essence of the flush privileges command is to extract the user information/permission settings in the current user and privilege tables from the mysql library (the built-in library of the MySQL database) into memory. After the MySQL user data and permissions are modified, if you want them to take effect directly without restarting the MySQL service, you need to execute this command.

Before, I got an error when changing the temporary password. It couldn’t log into my mysql, so there was the next problem:

Three. Questions

Sometimes this happens when we log in to Mysql and enter the password, so I found several methods on the Internet

mysql -u root -p

Enter Password > ‘Password’

Error: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

Or: Error: ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

4. Solution

1. Modify the my.in/my.cnf configuration file

Enter the mysql installation directory

Edit my.ini

Add skip-grant-tables under [mysqld] and save it.

2.Open the command line as an administrator

①Restart mysql:

1. net stop mysql 2. net start mysql

②Enter mysql and log in
mysql -u root -p
There is no need to enter a password, just press Enter (if Enter Password appears, just press Enter and you will be able to log in successfully)

③Enter use mysql to change the root password:
Update user set authentication_string=password(‘123456′) where user=’root’;
flush privileges;

④Exit:

Quit;

⑤Restart mysql again:

1. net stop mysql 2. net start mysql

⑥ Whether the test is successful means whether the login is successful.
mysql -u root -p

  Enter Password>’New Password’

There will be no mistakes and you can log in! ! !

(Another situation is that you entered the wrong password. If this is the first time you log in after initialization, if this happens, there is a high probability that the password is wrong. Please check the password carefully after initialization, there may be errors due to spaces and decimal points. Wrong input of equal symbols)

That’s the end of today’s sharing! See you next week!