Installing and uninstalling MySQL under the CentOS system

Source: Internet
Author: User

The CentOS7 Yum source does not seem to have MySQL by default. To solve this problem, we need to download the MySQL repo source first.

1. Download the MySQL repo source

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2. Install the MYSQL-COMMUNITY-RELEASE-EL7-5.NOARCH.RPM package

[[Email protected] ']$sudo rpm-ivh mysql-community-release-el7-5. noarch.rpm

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

3. Install MySQL

[[Email protected] sudo Yum Install Mysql-server

Follow the steps to install it, but after the installation is complete, there is no password and you need to reset the password.

4. Reset Password

Before resetting your password, you must first log in

[[Email protected] ']mysql-u root

This error may be reported at login:Error 2002 (HY000): Can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2)

The reason for this is the/var/lib/mysql access rights issue. The following command changes the owner of the/var/lib/mysql to the current user:

[[Email protected] sudo chown -R root:root/var/lib/mysql

Then, restart the service:

[Email protected] ']service mysqld Restar

Next login to reset Password:

[[Email protected] ']mysql-u root
MySQL >> Update user set Password=password ('123456') where user=> exit;

5. Open 3306 Ports

[[Email protected] sudo vim/etc/sysconfig/iptables

Add the following content:

3306 -j ACCEPT

Restart the firewall after saving:

[[Email protected] sudo service iptables restart

This allows the MySQL service to be connected from other clients as well.

CentOS Uninstall MySQL

Yum-style installation of MySQL

[[Email protected] Yum remove MySQL mysql-server mysql-libs compat-mysql51
[[Email protected] RM -rf/var/lib/mysql

[[Email protected] RM /ETC/MY.CNF

See if you have MySQL software :

[Email protected] ']rpm-qa| grep MySQL

If it exists, continue with the deletion.

RPM-style installation of MySQL

1. Check if MySQL is installed in RPM package on the system:

grep -i mysqlmysql-server-5.6. 1. el6.i686 MySQL-client-5.6. 1. el6.i686

2. Uninstall MySQL

[Email protected] ']# rpm-e mysql-server-5.6. 1. el6.i686
[[Email protected]  -E mysql-client-5.6. 1. el6.i686

3. Delete MySQL Service

grep -i mysql
[[Email protected]  --del MySQL

4. Remove the Distributed MySQL folder

Whereis Find /-name MySQL

5. Empty all relevant MySQL directories and files (/usr/lib/mysql,/usr/share/mysql)

[[Email protected] RM -rf/usr/lib/ MySQL
[[Email protected] rm -rf/usr/share/MySQL
[[Email protected] RM -rf/usr/my.cnf

With these steps, MySQL should have been completely uninstalled.

Installing and uninstalling MySQL under the CentOS system

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.