MySQL faq I have compiled on Cu

Source: Internet
Author: User
Tags mysql host mysql manual

Q: How to install lamp (Linux + Apache + MySQL + PHP)
A: [url] http://www.freelamp.com/1003235699/index_html#/url]

Q: How to install MySQL using rpm
A: First download the appropriate RPM package, such as downloading the file MySQL-5.0.15-0.i386.rpm
Use the following method to install:
# Rpm-ivhuMySQL-5.0.15-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.
# Rpm-ivhuMySQL-devel-5.0.15-0.i386.rpm
# Rpm-ivhuMySQL-client-5.0.15-0.i386.rpm

Q: How to install a compiled MySQL Binary Package
A: First download the appropriate binary package, such as downloading the file mysql-standard-4.1.13-pc-linux-gnu-i686.tar.gz
# Groupadd MySQL
# Useradd-G MySQL
# Cd/usr/local
# Tar zxf mysql-standard-4.1.13-pc-linux-gnu-i686.tar.gz
# Ln-s mysql-standard-4.1.13-pc-linux-gnu-i686 MySQL
# Cd MySQL
# Scripts/mysql_install_db -- user = MySQL
# Chgrp-r MySQL *
# Bin/mysqld_safe -- user = MySQL &
You can add related parameters by creating/etc/My. CNF or/usr/local/MySQL/data/My. CNF.

Q: How to compile MySQL
A: Take RedHat Linux 9.0 as an example:
Download file mysql-4.1.13.tar.gz
# Tar zxf mysql-4.1.13.tar.gz
# Cd mysql-4.1.13
#./Configure -- prefix =/usr/local/MySQL -- enable-validator/
-- With-mysqld-ldflags =-all-static -- localstatedir =/usr/local/MySQL/data/
-- With-Unix-socket-Path =/tmp/MySQL. Sock -- enable-Cycler/
-- With-charset = Complex -- With-low-memory -- With-Mit-threads
# Make
# Make install
# Groupadd MySQL
# Useradd-G MySQL
# Chgrp-r MySQL/usr/local/MySQL/
#/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.

Q: How to log on to MySQL
A: log on using the client tool provided by MySQL.
# Path_to_mysql/bin/MySQL-uuser-ppassword dateabase

Q: How can I modify the root password of MySQL?
A: If MySQL is running, killall-term mysqld is first killed.
Start MYSQL: path_to_mysql/bin/mysqld -- skip-grant-tables &
You can access MySQL without a password.
Then
Mysql> use MySQL
Mysql> Update user SET Password = PASSWORD ("new_pass") Where
User = "root ";
Mysql> flush privileges;
Kill MySQL again and start MySql in a normal way
Note: many new users do not use password = PASSWORD ("..."), but directly use password = "...", so it is difficult to change the password.

Q: Why can't I log on when mysqld is up? The error "/var/lib/MySQL. Sock" does not exist
A: 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 the IP address and connect to MySQL using TCP instead of local sock.
# 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

Q: How to change the MySQL user password?
A: There are roughly two methods:
1,
Mysql> mysql-uroot-pxxx MySQL
Mysql> Update user SET Password = PASSWORD ('new _ password') Where
User = 'user ';;
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.

Q: How to add a MySQL user
A: 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
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
The data can be used as needed. 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 refers to 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 data from the Internet.
Database, which can only be accessed through the web page on the MySQL host.
Mysql> grant select, insert, update, delete on mydb. * To Test2 @ localhost
Identified by "ABC ";
If you do not want Test2 to have a password, you can run another command to remove the password.
Mysql> grant select, insert, update, delete on mydb. * To Test2 @ localhost
Identified "";
In addition, you can insert a new record to the user table directly.

Q: How can I check the MySQL database?
A: mysql> show databases;

Q: How can I view tables in a database?
A: mysql> show tables;

Q: How to export data
A: There are several methods:
1. Use mysqldump
# Mysqldump-uuser-ppassword-B database -- tables Table1 -- tables Table2
> Dump_data_20051206. SQL
Detailed Parameters

2. Backup to Syntax
Mysql> Backup table tbl_name [, tbl_name...]
'/Path/to/backup/directory ';
For more information, see the MySQL manual.

3. mysqlhotcopy
# Mysqlhotcopy db_name [/path/to/new_directory]
Or
# Mysqlhotcopy db_name_1... db_name_n/path/to/new_directory
Or
# Mysqlhotcopy db_name./RegEx/
For more information, see the MySQL manual.

4. Select into OUTFILE
For more information, see the MySQL manual.

5. Client Command Line
# Mysql-uuser-ppassword-e "SQL statements" database> result.txt

Among the above methods, mysqldump is the most commonly used

Q: How to execute SQL statements on the command line
A: # mysql-uuser-ppassword-e "SQL statements" Database

Q: How to import backup files?
A: several common methods are as follows:
1. Files dumped by mysqldump
# Mysql-uuser-ppassword [database] <dump. SQL

2. The file type is the same as above. Use the source syntax.
Mysql> source/path_to_file/dump. SQL;

3. text files or CSV files stored in a certain format
# Mysqlimport [Options] database file1 [file2....]
For more information, see the MySQL manual.

4. The file type is the same as above. You can also use the load data syntax to import the file.
For more information, see the MySQL manual.

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.