MySQL8 Installation on Linux(Centos7)
Switch to root user or sudo user to avoid permission error.
Step 1. Setup Yum repository
wget https://repo.mysql.com/mysql80-community-release-el7-1.noarch.rpm
yum localinstall mysql80-community-release-el7-1.noarch.rpm -y
Step 2. Install MySQL 8 Community Server
yum install mysql-community-server
Step 3. Start MySQL Service
service mysqld start
Step 4. Show the default password for root user
When you install MySQL 8.0, the root user account is granted a temporary password. To show the password of the root user account, you use this command:
grep "A temporary password" /var/log/mysqld.log
Here is the output:
[Note] A temporary password is generated for root@localhost: hjkygMukj5+t783
Note that your temporary password will be different. You will need this password for changing the password of the root user account.
Step 5. MySQL Secure Installation
Execute the command mysql_secure_installation to secure MySQL server:
mysql_secure_installation
It will prompt you for the current password of the root account:
Enter password for user root:
Enter the temporary password above and press Enter. The following message will show:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
You will need to enter the new password for the root‘s account twice. It will prompt for some questions, it is recommended to type yes (y):
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Step 6. Restart and enable the MySQL service
Use the following command to restart the mysql service:
service mysqld restart
and autostart mysql service on system’s startup:
chkconfig mysqld on
Step 7. Connect to MySQL
Use this command to connect to MySQL server:
mysql -u root -p
It will prompt you for the password of the root user. You type the password and press Enter:
Enter password:
It will show the mysql command:
mysql>
Use the SHOW DATABASESto display all databases in the current server:
mysql> show databases;
Here is the output:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec)
To provide Remote access
CREATE USER 'root'@'%' IDENTIFIED BY 'Mysql@123'; // You should set Complicated Password
SELECT user,authentication_string,plugin,host FROM mysql.user;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'Mysql@123';
FLUSH PRIVILEGES;
MySQL5 Installation on Linux(Centos7)
1. sudo wget http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
2. sudo yum localinstall mysql57-community-release-el7-7.noarch.rpm
3.sudo yum install mysql-community-server
4.sudo service mysqld start
5.sudo service mysqld status
6. sudo grep 'temporary password' /var/log/mysqld.log (temp password)
//Please note the temporary password.
7. mysql_secure_installation
//reset password for root and allow remote access
8. mysql -u root -p
//If you want to allow remote access to particular IP
9. GRANT ALL PRIVILEGES ON *.* TO root@'172.168.1.10' IDENTIFIED BY '******';
//If you want to give global access
10.grant all privileges on *.* to 'root'@'%' IDENTIFIED BY '******';
******************************************************************
If you are facing access denied error for root user
Try following
SELECT `User`, `Grant_priv` FROM `mysql`.`user` WHERE `User` = 'root';
You will probably notice it returns a 'N' for Grant_priv. So do this:
UPDATE `mysql`.`user` SET `Grant_priv` = 'Y' WHERE `User` = 'root';
FLUSH PRIVILEGES;
SELECT `User`, `Grant_priv` FROM `mysql`.`user`;
or
mysql> flush privileges;
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
No comments:
Post a Comment