Install Mysql in Linux and mysql in linux

Source: Internet
Author: User

Install Mysql in Linux and mysql in linux
Background

  Not long ago, I began to learn how to deploy ambari. I encountered some problems when installing mysql. Now I have found some deployment procedures on the Internet to record them so that I can install mysql later.

 

Install Mysql 5.7.13 on Centos 7.2

Install yum as follows:

Wget http://yum.baseurl.org/download/x.x/yum-x.x.x.tar.gz
Tar xvf yum-x.x.x.tar.gz

Cd yum-x.x.x
Yummain. py install yum

The above is the general process in memory.

1. Download the mysql repo Source

Mysql does not exist in the yum source of CentOS 7.2 by default. You must first download the mysql repo source.

  • wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

 

2. Install the mysql57-community-release-el7-8.noarch.rpm package
  • rpm -ivh mysql57-community-release-el7-8.noarch.rpm --nodeps --force

After installing this package, you will get the yum repo source for two mysql:/etc/yum. repos. d/mysql-community.repo and/etc/yum. repos. d/mysql-community-source.repo

3. Install mysql
  • yum install mysql-server
4. Start the mysql Service

Check whether the MySQL service is started

service mysqld status

If the service is not started, run the following command to start the service:

service mysqld start
or
systemctl start mysqld

5. Reset the root password

MySQL5.7 will generate a random password for the root user after installation, instead of a blank password like the previous version.
You can change the root logon password in safe mode or use a random password to log on and change the password. The following is a random password.

The random password generated by MySQL for the root user can be found through the mysqld. log file:

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

Modify the password of the root user: (the password policy of MySQL is complicated and the password that is too simple will be rejected)

  • Mysql-u root-pmysql> Enter password: (Enter the random PASSWORD just queried) mysql> SET password FOR 'root' @ 'localhost' = "root-123 "; mysql> exit

Log on with the new root password:

  • mysql -u root -pRoot-123

 

If the preceding method cannot be modified, you can use the following security mode to modify root:

Disable the systemctl stop mysqld service. servicevi/etc/my. add skip-grant-tables under cnf mysqld to save and exit the start service systemctl start mysqld. servicemysql-u root directly press ENTER use mysqlupdate user set authentication_string = password ('root-123 ') where User = 'root' and Host = 'localhost'; flush privileges; exit; vi/etc/my. cnf deletes the skip-grant-tables statement, saves it, and restarts the mysql service systemctl restart mysqld. service again to log on to mysql-u root-pRoot-123 if the operation appears the following prompt: You must reset your password using alter user statement before executing this statement. set password = password ('root-123 ') again ');

 

 

6. Open Port 3306

Allow user name root Password Root-123456 to connect to mysql server from any host

mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root-123456' WITH GRANT OPTION;mysql>FLUSH PRIVILEGES;mysql>exit;
  • Enable external access to mysql 3306 through the firewall
firewall-cmd --zone=public --add-port=3306/tcp --permanentfirewall-cmd --reload
Summary

Mysql is configured in detail above. You can use systemctl restart mysqld. service to display the current configuration and status after you run the command (ps-ef | grep mysql) to view the mysql status. At the beginning, I still had a lot to understand. I hope you can give me some advice.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.