Install and uninstall mysql and yummysql in yum in linux

Source: Internet
Author: User

Install and uninstall mysql and yummysql in yum in linux

1. Check whether the installation is successful:

Yum list installed mysql *

Rpm-qa | grep mysql *

2. Check whether the installation package is available:

Yum list mysql *

 

3. Install the mysql client:

Yum install mysql

 

4. Install the mysql server:

Yum install mysql-server

 

Yum install mysql-devel

 

5. Start & stop

 

Database Character Set settings

Add default-character-set = utf8 to the mysql configuration file/etc/my. cnf.

 

Start the mysql service:

Service mysqld start or/etc/init. d/mysqld start

Start startup:

Chkconfig-add mysqld to check whether the startup setting is successful. chkconfig -- list | grep mysql *

 

Mysqld 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable

Stop:

Service mysqld stop
If it cannot be started, check whether the mysqld service is enabled in the service.

6. log on

 

Create a root administrator:

Mysqladmin-u root password 123456

Www.2cto.com

Logon:

Mysql-u root-p: enter the password.

Forgot password:

Service mysqld stop

 

Mysqld_safe -- user = root -- skip-grant-tables

 

Mysql-u root

 

Use mysql

 

Update user set password = password ("new_pass") where user = "root ";

 

Flush privileges;

 

7. Remote Access

 

1. Modify localhost
Change the "host" entry in the "user" table in the "mysql" database to "%" from "localhost"
Mysql> use mysql;
Mysql> update user set host = '%' where user = 'root ';
Mysql> select host, user from user;
Mysql> flush privileges;

 

2. Specify authorization
Use myuser/mypassword to connect to the mysql server from any host:
Grant all privileges on *. * TO 'myuser' @ '%' identified by 'mypassword' with grant option;

Use myuser/mypassword to connect to the mysql server from a host with the ip address 192.168.225.166:
Grant all privileges on *. * TO 'myuser' @ '192. 168.225.166 'identified BY 'mypassword' with grant option;

 

3. wildcard authorization
Mysql-h localhost-u root
Mysql>Grant all privileges on *. * TO 'root' @ '%' with grant option;// Grant data access permissions to any host as root
Mysql>Flush privileges;

 

Solve the problem that Mysql cannot be remotely connected. 

1. Is the Mysql port correct?
PassNetstat-ntlpCheck the port usage. Generally, the port is 3306. A port is used to connect to MySQl using tools. For example, My Admin \ My Query Browser \ MySQl Front.

2. Check whether the user permissions are correct.
The user table of the mysql database has two records: localhost and % (for security purpose, % can be replaced by the IP address you need to connect to the external database ).

3. Check whether skip-networking has been injected in/etc/mysql/my. cnf.
Need to be noted out
ERROR: ERROR 2003 (HY000): Can't connect to MySQL server on '192. 168.51.112 '(192)

 

Sudo gedit/etc/mysql/my. cnf
# Skip-external-locking

# Bind-address = 127.0.0.1

Skip-name-resolve


4. Check whether iptables is stopped. If no, the connection fails.
Service iptables stop is temporarily disabled.
ERROR: ERROR 2003 (HY000): Can't connect to MySQL server on '192. 168.51.112 '(192)

 

 

8,LinuxSeveral important MySQL Directories

Www.2cto.com

Database directory

/Var/lib/mysql/

Configuration File

/Usr/share/mysql (mysql. server command and configuration file)

Related commands

/Usr/bin (commands such as mysqladmin mysqldump)

Start script

/Etc/rc. d/init. d/(directory for starting the script file mysql)


Uninstall mysql
1. Check whether mysql is installed before.
Command: rpm-qa | grep-I mysql
We can see two mysql packages:
Mysql-*... *. RHEL **
Mysqlclient *. RHEL **
2. Delete mysql
DELETE command: rpm-e -- nodeps package name
(Rpm-ev mysql-*. RHEL *)
3. Delete the development header files and libraries of old mysql versions.
Command: rm-fr/usr/lib/mysql
Rm-fr/usr/include/mysql
Note: After uninstallation, data in/var/lib/mysql and/etc/my. cnf will not be deleted. If you are sure it is useless, manually delete it.
Rm-f/etc/my. cnf
Rm-fr/var/lib/mysql

There is another method

Mysql installed in yum Mode

 

1, yum remove mysql-server mysql-libs compat-mysql51

2. rm-rf/var/lib/mysql

3. rm/etc/my. cnf

 

Check whether there is any mysql software:
Rpm-qa | grep mysql

If yes, continue to delete it.

 

Mysql installed in rpm Mode

 

 

A) Check whether mysql is installed with an rpm package in the system:

 

[Root @ localhost opt] # rpm-qa | grep-I mysql
MySQL-server-5.6.17-1.el6.i686
MySQL-client-5.6.17-1.el6.i686

 

B) uninstall mysql

[Root @ localhost local] # rpm-e MySQL-server-5.6.17-1.el6.i686
[Root @ localhost local] # rpm-e MySQL-client-5.6.17-1.el6.i686

C) delete the mysql Service

[Root @ localhost local] # chkconfig -- list | grep-I mysql
[Root @ localhost local] # chkconfig -- del mysql

D) Delete the scattered mysql folder.

[Root @ localhost local] # whereis mysql or find/-name mysql

 

Mysql:/usr/lib/mysql/usr/share/mysql

Clear all related mysql directories and files
Rm-rf/usr/lib/mysql
Rm-rf/usr/share/mysql

Rm-rf/usr/my. cnf

 

After completing the preceding steps, mysql should have been fully uninstalled.

The entire process of mysql uninstallation and installation in linux

Uninstall mysql

1. Check whether mysql is installed before.

Command: rpm-qa | grep-I mysql

We can see two mysql packages:

Mysql-4.1.12-3.RHEL4.1

Mysqlclient10-3.23.58-4.RHEL4.1

2. Delete mysql

DELETE command: rpm-e -- nodeps package name

(Rpm-ev mysql-4.1.12-3.RHEL4.1)

3. Delete the development header files and libraries of old mysql versions.

Command: rm-fr/usr/lib/mysql

Rm-fr/usr/include/mysql

Note: After uninstallation, data in/var/lib/mysql and/etc/my. cnf will not be deleted. If you are sure it is useless, manually delete it.

Rm-f/etc/my. cnf

Rm-fr/var/lib/mysql

Install mysql

Preparations before installation: Two rpm packages

MySQL-client-5.1.20-0.glibc23.i386.rpm

MySQL-server-5.1.20-0.glibc23.i386.rpm

1. Install the server:

Command: rpm-ivh MySQL-server-5.1.20-0.glibc23.i386.rpm

After the installation is successful ....

Warning: MySQL-server-5.1.20-0.glibc23.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5

Preparing... ######################################## ### [100%]

1: mySQL-server ##################################### ###### [100%]

080220 13:58:27 [Note] Plugin 'innodb' disabled by command line option

080220 13:58:28 [Note] Plugin 'innodb' disabled by command line option

Please remember to set a password for the MySQL root USER!

To do so, start the server, then issue the following commands:

/Usr/bin/mysqladmin-u root password 'new-password'

/Usr/bin/mysqladmin-u root-h localhost. localdomain password 'new-password'

See the manual for more instructions.

Please report any problems with the/usr/bin/mysqlbug script!

The latest information about MySQL is available on the web

Http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

Starting MySQL. [OK]

2. Install the client

Command: rpm-ivh MySQL-client-5.1.20-0.glibc23.i386.rpm

Successful Performance:

[Root @ localhost ~] # Rpm-ivh MySQL-client-5.1.20-0.glibc23.i386.rpm

Warning: MySQL-client-5.1.20-0.glibc23.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5

Preparing... ######################################## ### [100%]

1: mySQL-client ##################################### ###### [100%]

3. log on to mysql

The command used to log on to MySql is mysql. the syntax of mysql is as follows:

Mysql [-u username] [-h host] [-p [password] [dbname]

Username and password are the username and password of MySQL respectively. The initial management account of mysql is root, and there is no password. Note: This root user is not a Linux system user. The default MySQL user is root. Because there is no password at first, you only need to type mysql for the first time.

[Root @ localhost ~] # Mysql

Welcome to the MySQL monitor. Commands end with; or \ g.

Your MySQL connection id is 2

Server version: 5.1.20-beta MySQL Community Server (GPL)

Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.

Mysql>

The prompt "mysql>" appears. Congratulations! The installation is successful!

The logon format after the password is added is as follows:

Mysql-u root-p

Enter password: (Enter the password)

-U is followed by the user name.-p requires the password. Press enter and enter the password at the Enter password.

Note: This mysql file is located in the/usr/bin directory. It is not a file with the Startup file/etc/init. d/mysql described later.

Supplement:

Detailed process of installing, configuring, and detaching mysql through rpm packages.

Take MySQL-server-4.0.14-0.i386.rpm as an example, put it under the/data Directory

Cd/data

Rpm-ivh MySQL-server-4.0.14-0.i386.rpm

After installation is complete, there will be a mysql STARTUP script in the/usr/share/mysql directory mysql. server and sample configuration files (such as my-huge.cnf, my-large.cnf, my-medium.cnf)

Copy an example configuration file as the mysql configuration file:

Cp/usr/share/mysql/my-medium.cnf/etc/my. cnf

After the rpm package is installed, mysql is automatically installed as a system service. Therefore, you can run the following command to start or stop mysql:

Start mysql

/Etc/init. d/mysql start or service mysql start

Stop mysql

/Etc/init. d/mysql stop or service mysql stop

At this point, the mysql service has been installed and configured.

Install the mysql client

Rpm-ivh MySQL-client-4.0.14-0.i386.rpm

After mysql is installed, the directory structure is as follows:

The tool program is in the/usr/bin directory --- ls/usr/bin/mysql *

Server program/usr/sbin/mysqld

Data directory/var/lib/mysql

By default, mysql writes the Error Log File, binary log file and process file in the/var/lib/mysql directory, such as localhost. err, localhost. pid, localhost-bin.001, etc.

To change these conditions, modify the/etc/my. cnf file.

For example, to write a log file in the/var/log directory, you can add the following two lines to the my. cnf file:

[Mysqld_safe]

Err-log =/var/log/mysqld. log

There is a utility/usr/bin/mysql_install_db which can be used to initialize the mysql database, that is, to create the/var/log/mysql directory and to create the mysql database (mysql authorization table and other information) and test Database (empty database), If you accidentally delete the/var/log/mysql directory, you can use this program to initialize.

Uninstall mysql

Rpm-qa | grep-I mysql

Rpm-ev MySQL-server-4.0.14-0 MySQL-client-4.0.14-0

Data in/var/lib/mysql and/etc/my. cnf will not be deleted after uninstallation. If it is determined that it is useless, it will be deleted manually.

Rm-f/etc/my. cnf

Rm-rf/var/lib/mysql

Mysql 1130 error solution:

This error occurs when you connect to MySQL through mysql-Front or mysql administrator.

ERROR 1130: Host ***. *** is not allowed to connect to this MySQL server

This indicates that the connected user account does not have the permission for remote connection and can only log on to the Local Machine (localhost.

You need to change the host entry in the user table of the mysql database.

Rename localhost as %

Specific steps: log on to mysql

Use mysql first;

An error occurs when the update method is provided by others.

Mysql> update user set host = '%' where user = 'root ';

ERROR 1062 (23000): Duplicate entry '%-root' for key 'Primary'

Then, you can view the host information of the database as follows:

Mysql> select host from user where user = 'root ';

+ ----------------------- +

| Host |

+ ----------------------- +

| % |

| 127.0.0.1 |

| Localhost. localdomain |

+ ----------------------- +

3 rows in set (0.00 sec)

The host already has the value %, so run the following command:

Mysql> flush privileges;

Connect to mysql administrator again... successful !!!

Tar.gz version installation:

Version 1:

1. Place the MYSQL installation package and decompress it to/usr/local.

Tar zxvf mysql-standard-5.0.27-linux-i686-glibc23.tar.gz

2. Create a symbolic link for the Directory

Ln-s mysql-standard-4.0.24-pc-linux-gnu-i686 mysql

3. Create a MYSQL group and user

Groupadd mysql

Useradd-g mysql

4. Change the user and group of the mysql directory

Chown-R mysql. # ensure that the current directory is/usr/lcoal/mysql.

Chgrp-R mysql.

5. Run the configuration script as a mysql user

Su mysql # Switch to mysql user

Cd/usr/local/mysql # note that after switching the user, the working directory is no longer/usr/local/mysql. So you have to repeat it.

./Configure # execute the configuration script

6. Go to the database and check whether the installation is successful.

/Usr/local/mysql/bin/mysql

If a mysql prompt is displayed and you enter the prompt, the installation is successful!

7. Automatically enable mysql service when the system starts

Su-# switch back to root user

Cd/usr/local/mysql

Cp support-files/mysql. server/etc/rc. d/init. d/mysql # copy the mysql script file to the startup directory of the system.

Cd/etc/rc. d/init. d/

Chmod + x mysql # change to Executable File Attributes

Chkconfig -- add mysql # add mysql to the startup service list

Chkconfig mysql on # enable mysql service automatically when the system starts

After the system is restarted, run/usr/local/mysql/bin/mysql. If a mysql prompt is displayed, the entire installation is successful.

Version 2:

Mysql-standard-4.0.24-pc-linux-gnu-i686.tar.gz is mysql4.0.24 version of the installation file, is a binary compressed package, so our Installation Method for Binary distribution installation.

Installation steps:

1. Copy mysql-standard-4.0.24-pc-linux-gnu-i686.tar.gz to a directory

2. shell> tar zvxf mysql-standard-4.0.24-pc-linux-gnu-i686.tar.gz

3. The above command will generate a mysql-standard-4.0.24-pc-linux-gnu-i686 folder under the current directory

4. shell> music video mysql-standard-4.0.24-pc-linux-gnu-i686/usr/local/mysql

5. The above command is to all the stuff under the mysql-standard-4.0.24-pc-linux-gnu-i686, cut to/usr/local/mysql, this step is for the convenience of the future.

6. shell> groupadd mysql adds a user group named mysql.

7. shell> useradd-g mysql Add a user named mysql in the mysql user group

If the preceding two commands cannot be executed, switch to the root user for execution.

Shell> su root-

8. shell> cd/usr/local/mysql

9. shell> cp support-files/my-medium.cnf/etc/my. cnf

In this case, I will ask whether to overwrite the duplicate file and answer "y ".

10. shell> scripts/mysql_install_db -- user = mysql

Initialize the database as a mysql user.

11. shell> chown-R root

Note the following: Set the owner of all files and subdirectories in the current directory.

Set as root user

12. shell> chown-R mysql data

Sets the owner of the data directory in the current directory as a mysql user.

13. shell> chgrp-R mysql.

Note that the file group in the current directory is set to the mysql group.

14. shell> bin/mysqld_safe -- user = root &

If "... Ended!

15. Press enter to display shell>

Now you can

Run the shell> netstat-atln command to check whether port 3306 is enabled.

You can also use shell> ps-ef | grep mysqld to view the mysqld process in the current system.

Or directly run shell> bin/mysql-u root to enter the mysql client and perform mysql operations.

Or shell> bin/mysqladmin shutdown to stop mysql Service

Remember: At this time, your root user has no password, and any identity can be entered with root. You can

Use shell> bin/mysqladmin-u root password 'new password' to set the password for the root user. This password is required when you enter the mysql client and stop the mysql service.

Tip: when starting a single service, you can modify the/etc/my. cnf file to configure

You can open my. cnf in the VI editor.

Shell> vi my. cnf open my. cnf

Find the following section

[Mysqld]

Port = 8888

Socket =/tmp/mysql. sock

You can add the corresponding configuration

Log =/var/log/mysql. log

Datadir =/free/mysqldbf

For example, log =/* changes the log storage location.

Datadir =/free/mysqldbf changes the data storage location

Hope to be helpful to friends who encounter the same problem

Common commands:

Start MySQL:

Service mysql start

/Etc/init. d/mysql start

/Usr/share/mysql. server start

[Mysql. server]

# Comment out the basedir line; otherwise, MySql may not be able to start

# It is said to be a MySql bug

# Basedir =/var/lib

When the root user logs on, mysql is automatically started:

Add one line to the/root/. bash_profile file:

/Usr/share/mysql. server start

View the startup log:

/Var/log/messages

Show all MySQL users:

Use mysql;

Select host, user, password from user;

Add a MySQL user (user name: user1, password: SQL ):

Grant all on *. * to user1 @ '%' identified by 'SQL' with grant option;

Delete a MySQL user:

Delete from user where user = 'user1 ';

Configure environment variables:

PATH = $ JAVA_HOME/bin: $ CATALINA_HOME/bin:/usr/local/mysql/bin: $ PATH

 

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.