MySQL 8 is the latest version available for the installation. MySQL is the most popular database server for Linux systems, it also supports a large number of platforms. This tutorial will help you to Install MySQL Server 8.0 Community Edition on CentOS/RHEL 7/6 LInux using the package manager.
Step 1 – Setup Yum Repository
First, you need to enable MySQL yum repository in your system provided by MySQL. Execute one of the below commands as per your operating system version.
### On CentOS/RHEL 7 system ### rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm ### On CentOS/RHEL 6 system ### rpm -Uvh https://repo.mysql.com/mysql80-community-release-el6-3.noarch.rpm
Step 2 – Install MySQL Community Server
The MySQL yum repository contains multiple repositories configuration for multiple MySQL versions. So first disable all repositories in mysql repo file.
sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo
Then execute one of the followings commands as per your operating system to install MySQL.
yum --enablerepo=mysql80-community install mysql-community-server ## CentOS & RedHat dnf --enablerepo=mysql80-community install mysql-community-server ## Fedora Systems
Step 3 – Start MySQL Service
Start the MySQL server using the following command from the Linux terminal.
Using SysVinit
service mysqld start
Using Systemd
systemctl start mysqld.service
Step 4 – Find default root Password
With the installation of MySQL 8.0, a temporary password is created for the MySQL root user. You can find the temporary password generated in log files.
grep "A temporary password" /var/log/mysqld.log
Output:
[Note] [MY-010454] [Server] A temporary password is generated for root@localhost: VWa>Bo9xFUrs
Step 5 – MySQL Post Install Setup
After installing MySQL first time, execute mysql_secure_installation
command to secure MySQL server. It will prompt for few question’s, we recommended to say yes ( y ) for each.
mysql_secure_installation
Enter password for user root: The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password: Change the password for root ? ((Press y|Y for Yes, any other key for No) : n 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 MySQL Service
The MySQL installation has been successfully completed. Now restart the service and set up autostart on system bootup.
### Using SysVinit service mysqld restart chkconfig mysqld on ### Using Systemd systemctl restart mysqld.service systemctl enable mysqld.service
Step 7 – Working with MySQL
Now connect mysql database server Linux shell using below command. It will prompt for the password for authentication. On successful login, you will get the MySQL command prompt, where we can execute SQL queries.
mysql -h localhost -u root -p
After login, You can use the following commands to create a new database, create a user and assign privileges to the user on the database. Change values as per your requirements.
1 2 3 4 5 6 7 8 9 10 11 | ### CREATE DATABASE mysql> CREATE DATABASE mydb; ### CREATE USER ACCOUNT mysql> CREATE USER 'dbuser'@'192.168.10.101' IDENTIFIED BY 'secret'; ### GRANT PERMISSIONS ON DATABASE mysql> GRANT ALL ON mydb.* TO 'dbuser'@'192.168.10.101'; ### RELOAD PRIVILEGES mysql> FLUSH PRIVILEGES; |
10 Comments
Excellent. Thank you very much. God bless you for sharing the knowledge.
Thank you for clearing the process up. I have been working on this install for two days. The information that I found was useless.
I ran a search, saw the TecAdmin link, which I recognized from previous issues opened the link and 10 minutes later I have a running server and documented install. You make me look good!
With all the confusion around MariaDB/MySQL and CentOS changing hands, it is tedious trying to keep up with all the changes, I need to be producing not floundering. I did not find any mention of the Community repo before this article. I looked too. Reading package notes, and then the MariaDB website, (a big wabbit hole) there was never any mention of the community repo. NONE!
In the future I will look to here first.
Thank you.
Hi, I’m kinda new in this… by the way I need help, what is the password for user root in step 5?, I put the one from the begining of my fedora installation and i tried with the one generated in step 4, both send me an error: access denied for user root…….
Apreciate all your effort, thank you
Hello,
thanks for this valuable post.
I have a question if you or another user can answer it.
Why in mysql 8 the OS user mysql is disabled ? I mean by disabled, we cannot connect to because the shell in /etc/passwd is set to /bin/false ?
It means that for managing mysql service, we will always need to log as root which goes in contradiction with our needs to separate roles.
Any explanation please?
Thanks again for the quality of the post.
You can still login as mysql. I had the same problem with Apache. Use this syntax:
su -s /bin/bash mysql
It will log you in, no spiffy environment settings, useful in so many ways like checking permissions and what not.
Thanks, Very clear and step by step doc…
Thanks my friend. Very neat article.
Very Good. It is very hard to find proper installation documentation guides these days. Your document is very clear and straightforward.
Awesome! Thank you so much. You save too much time for me.
Thank you very much. Very useful tutorial well explained.