By Sheldon L | Published at 2019-09-14 | Updated at 2019-10-01 |
For Debian or Ubuntu, see MySQL Community Server (for APT);
After installation, see Postinstallation Setup and Testing
For all tutorials: MySQL 8.0 Reference Manual
For CentOS MariaDB Database (a fork of MySQL for RedHat Enterprise Linux) is default;
If still want MySQL for CentOS 7 or RedHat 7, refer to MySQL Community Server (for Yum);
Tip: remember the root passwd
# Check if installed already
rpm -qa | grep mysql
# !! this line won't install mysql, but update Mariadb, for Mariadb is default for CentOS
yum install mysql
# !! remove Mariadb first
yum remove mysql
# Download mysql repo source and install
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
sudo yum localinstall mysql80-community-release-el7-3.noarch.rpm
# Check if mysql's yum repo is got
cd /etc/yum.repos.d/
ls
# OR
yum repolist enabled | grep "mysql.*-community.*"
# Return:
# 'mysql-community.repo'
# 'mysql-community-source.repo'
# Install mysql server
sudo yum install mysql-community-server
# This installs the package for MySQL server (mysql-community-server)
# and also packages for the components required to run the server,
# including packages for the client (mysql-community-client),
# the common error messages and character sets for client and server (mysql-community-common),
# and the shared client libraries (mysql-community-libs).
# Check
rpm -qa | grep mysql
# Starting the MySQL Server
service mysqld start
# Get temperary passwd and set root's passwd and set a custom password for the superuser account
sudo grep 'temporary password' /var/log/mysqld.log
mysql -uroot -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!'; # ';' is a must!
# Relogin to check
# Allow service mysql (mariadb) through firewall.
firewall-cmd --add-service=mysql
# Secure mysql (mariadb) server
/usr/bin/mysql_secure_installation
Same as on server.
# Open mysql by root
mysql -u root -p
# Tip: don't left over ';' in following sql langage
# Authorize a new user at localhost
GRANT ALL PRIVILEGES ON *.* TO username@localhost IDENTIFIED BY ‘root_password‘;
# Instead, connect to remote MySQL:
GRANT ALL PRIVILEGES ON *.* TO root@ip_adress IDENTIFIED BY ‘root_password‘ WITH GRANT OPTION;
# Check all users, several options:
select * from mysql.user;
select user, password, host from mysql.user;
desc mysql.user;