如何在CentOS / RHEL 7.4 / 6.9和Fedora 27/26/25上安装MySQL 8.0 / 5.7

1 篇文章 0 订阅

MySQL is an opensource, Relational Database Management System. MySQL is a most popular database server for Linux systems, it also supports a large number of platforms. In MySQL, we can easily create a stored procedure and execute SQL queries. MySQL Community Edition is a freely downloadable version and uses for your applications.

In this tutorial, you will get details to how to Install MySQL Server (community edition) on CentOS/RHEL 7.4/6.9, Fedora 27/26/25 using the default package manager.

Step 1 – Enable MySQL Yum Repository

First, we need to add MySQL yum repository in our system provided by MySQL. Execute one of below command as per your operating system version.

### On CentOS/RHEL 7 system ###
# rpm -Uvh https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm

### On CentOS/RHEL 6 system ###
# rpm -Uvh https://repo.mysql.com/mysql57-community-release-el6-11.noarch.rpm

### On Fedora 26 system ###
# rpm -Uvh https://repo.mysql.com/mysql57-community-release-fc26-10.noarch.rpm

### On Fedora 25 system ###
# rpm -Uvh https://repo.mysql.com/mysql57-community-release-fc25-10.noarch.rpm

### On Fedora 24 system ###
# rpm -Uvh https://repo.mysql.com/mysql57-community-release-fc24-10.noarch.rpm

Step 2 – Install MySQL Community Server

As we have successfully added MySQL yum repository in our system. Let’s move for MySQL installation. Execute below command to install MySQL server on your system. This will also install some other dependencies in the system.

Install MySQL 5.7:

# yum install mysql-community-server     ## CentOS, RHEL 7  
# dnf install mysql-community-server     ## Fedora 26/25/24 

Install MySQL 8.0:

# yum --enablerepo=mysql80-community install mysql-community-server     ## CentOS, RHEL 7 
# dnf --enablerepo=mysql80-community install mysql-community-server     ## Fedora 26/25/24 

Step 3 – Find MySQL root Password

With the installation of MySQL 8.0/5.7, 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

[Note] A temporary password is generated for root@localhost: hosygMikj1+t636

Step 4 – Start MySQL Service

Start the MySQL server using the following command from Linux terminal.

Using SysVinit

# service mysqld start

Using Systemd

# systemctl start mysqld.service

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
New password:

Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : No

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!

Step 6 – Restart and Enable MySQL Service

After completing all MySQL installation steps and doing all initial settings, restart MySQL service using the following command.

### Using SysVinit
# service mysqld restart

### Using Systemd
# systemctl restart mysqld.service

Also, enable service to auto start on system reboot with the following command.

### Using SysVinit
# chkconfig mysqld on

### Using Systemd
# 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 MySQL command prompt, where we can execute SQL queries.

# mysql -h localhost -u root -p 

After login, You can use 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;

获取MySQL的临时密码

为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于error log的位置,如果安装的是RPM包,则默认是/var/log/mysqld.log。 
只有启动过一次mysql才可以查看临时密码

grep 'temporary password' /var/log/mysqld.log

 
这里的密码是YdsGaxOq>2n!

 

使用默认的密码登陆

mysql -uroot -p

用该密码登录到服务端后,必须马上修改密码,不然会报如下错误:


mysql> select @@log_error;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';

如果密码设置太简单出现以下的提示

如何解决ERROR 1819 (HY000): Your password does not satisfy the current policy requirements呢? 这里直接提供解决方案文末有详细的说明

必须修改两个全局参数: 
首先,修改validate_password_policy参数的值

mysql> set global validate_password_policy=0; 

再修改密码的长度

mysql> set global validate_password_length=1;

再次执行修改密码就可以了

ALTER USER 'root'@'localhost' IDENTIFIED BY 'root123';

 

授权其他机器登陆

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;

FLUSH  PRIVILEGES;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值