Correct usage of linux MySQL

Source: Internet
Author: User
Tags mysql host import database

The following articles mainly introduce the specific use of linux MySQL and the description of some important matters worth attention in the actual operations of linux MySQL, the following describes the specific usage of linux MySQL. I hope it will be helpful in your future studies.

Where is the MySQL Data Inventory (Chen Xu)

1. If the rpm package is used for installation, the directory name of the database should be in the/var/lib/MySQL directory.

2. If the source code is installed in/usr/local/MySQL, use the database name as the directory name in/usr/local/MySQL/var.

5002 export and import data from linux MySQL (Chen Xu)

Export Database

MySQLdump Database Name> file name

Import Database

MySQLadmin create database name

MySQL database name <file name

5003 forget the root password of MySQL (Chen Xu)

 
 
  1. # service MySQL stop  
  2. # MySQLd_safe --skip-grant-tables &  
  3. # MySQLadmin -u user password 'newpassword''  
  4. # MySQLadmin flush-privileges 

5004 quick installation of php/MySQL (Chen Xu)

Make sure that all rpm packages starting with MySQL and php-MySQL are found from the installation disc using the system's built-in apache, and then run # rpm-ivh MySQL *. rpm php-MySQL *. rpm; MySQL_install_db; service MySQL start

5005 modify the root password of linux MySQL (Chen Xu, yejr)

There are roughly two methods:

1. MySQL> MySQL-uroot-pxxx MySQL

 
 
  1. MySQL>update user set passwordpassword=password('new_password') where user='user';  
  2. MySQL>flush privileges; 

2. Format: MySQLadmin-u username-p old password New password

# MySQLadmin-uroot-password ab12

Note: because the root account does not have a password at the beginning, the old-p password can be omitted.

5006 how to install MySQL (yejr) using rpm)

First download the appropriate rpm package, such as downloading the file MySQL-5.0.19-0.i386.rpm

Use the following method to install:

# Rpm-ivhuMySQL-5.0.19-0.i386.rpm

Generally, after this rpm package is installed, only the MySQLd service functions are available. Other related client programs and Development Kits need to be installed separately.

 
 
  1. #rpm -ivhU MySQL-devel-5.0.19-0.i386.rpm  
  2. #rpm -ivhU MySQL-client-5.0.19-0.i386.rpm 

5007 how to install the compiled MySQL Binary Package (yejr)

First download the appropriate binary package, such as downloading the file MySQL-standard-4.1.13-pc-linux-gnu-i686.tar.gz

 
 
  1. #groupadd MySQL  
  2. #useradd -g MySQL MySQL  
  3. #cd /usr/local  
  4. #tar zxf MySQL-standard-4.1.13-pc-linux-gnu-i686.tar.gz  
  5. #ln -s MySQL-standard-4.1.13-pc-linux-gnu-i686 MySQL  
  6. #cd MySQL  
  7. #scripts/MySQL_install_db --user=MySQL 
  8. #chgrp -R MySQL *  
  9. #bin/MySQLd_safe --user=MySQL & 

You can add related parameters by creating/etc/my. cnf or/usr/local/MySQL/data/my. cnf.

5008 how to compile MySQL (yejr) by yourself)

Take redhat linux 9.0 as an example:

Download file linux MySQL-4.1.13.tar.gz

 
 
  1. #tar zxf MySQL-4.1.13.tar.gz  
  2. #cd MySQL-4.1.13  
  3. #./configure --prefix=/usr/local/MySQL --enable-assembler \  
  4. --with-MySQLd-ldflags=-all-static --localstatedir=/usr/local/MySQL/data \  
  5. --with-unix-socket-path=/tmp/MySQL.sock --enable-assembler \  
  6. --with-charset=complex --with-low-memory --with-mit-threads  
  7. #make  
  8. #make install  
  9. #groupadd MySQL  
  10. #useradd -g MySQL MySQL  
  11. #chgrp -R MySQL /usr/local/MySQL/  
  12. #/usr/local/MySQL/bin/MySQLd_safe --user=MySQL & 

You can add related parameters by creating/etc/my. cnf or/usr/local/MySQL/data/my. cnf.

5009 how to log on to MySQL (yejr)

Use the client tool provided by MySQL to log on

# PATH_TO_MySQL/bin/MySQL-uuser-ppassword dateabase

5010 when MySQLd is up, but cannot log on, the prompt "/var/lib/MySQL. sock" does not exist (yejr)

In most cases, because your MySQL is installed in rpm mode, it will automatically find the/var/lib/MySQL. sock file,

Log on to MySQL through a unix socket.

Common solutions:

1. Create/modify the/etc/my. cnf file and add/modify at least one line.

[MySQL]

[Client]

Socket =/tmp/MySQL. sock

# Write the correct location of your MySQL. sock Here, usually either under/tmp/or under/var/lib/MySQL/

2. Specify an IP address and connect to MySQL using tcp instead of local sock.

# Linux MySQL-h127.0.0.1-uuser-ppassword

3. Add a connection for MySQL. sock. For example, if the actual MySQL. sock is under/tmp /,

# Ln-s/tmp/MySQL. sock/var/lib/MySQL. sock

5011 how to add a MySQL user (yejr)

Format: grant select on database. * to username @ login host identified by "password"

Example 1: Add a user named "test1" with the password "abc" so that the user can log on to any host and have the permission to query, insert, modify, and delete all databases. First, use the root user to connect to MySQL, and then type the following command:

MySQL> grant select, insert, update, delete on *. * to test1 @ "%" Identified by "abc ";

However, the User Added in Example 1 is very dangerous. If someone knows the password of test1, then he can log on to your MySQL database on any computer on the internet and do whatever he wants for your data. For the solution, see Example 2.

Example 2: Add a user named "test2" with the password "abc" so that the user can only log on to localhost and query, insert, modify, and delete the Database "mydb". localhost indicates the local host, that is, the host where the MySQL database is located). In this way, the user knows the password of test2 and cannot directly access the database from the internet, it can only be accessed through a web page on the linux MySQL host.

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.