Installation and configuration of mysql in linux

Source: Internet
Author: User

1. Download the MySQL Installation File
The following two files are required to install MySQL:
MySQL-server-4.0.23-0.i386.rpm
MySQL-client-4.0.23-0.i386.rpm
Open this webpage at http://www.mysql.com/downloads/mysql-4.0.html, pull down the webpage to the latest Linux x86 RPM downloads option, find the "Server" and "Client programs" items, and download the above two rpm files.
2. Install MySQL
The rpm file is a software installation package developed by Red Hat. rpm frees Linux from complicated procedures when installing software packages. The frequently used parameter of this command during installation is-ivh, where I indicates that the specified rmp package will be installed, and V indicates the detailed information during installation, h indicates that the "#" symbol appears during the installation to display the current installation process. This symbol will not stop until the installation is complete.
1) install the server
Run the following command in the directory with two rmp files:
[Root @ test1 local] # rpm-ivh MySQL-server-4.0.23-0.i386.rpm
The following information is displayed.
Warning: MySQL-client-4.0.23-0.i386.rpm
Signature: NOKEY, key ID 5072e1f5
Preparing... ######################################## ### [100%] This article is from tutorial network: http: // w
1: mySQL-server ##################################### ###### [100%]
...... (Omitted)
/Usr/bin/mysqladmin-u root password 'new-password'
/Usr/bin/mysqladmin-u root-h test1 password 'new-password'
...... (Omitted)
Starting mysqld daemon with databases from/var/lib/mysql
If the preceding information is displayed, the Server installation is complete. Run netstat to check whether the Mysql port is opened. If yes, the service is started and the installation is successful. The default Mysql port is 3306.
[Root @ test1 local] # netstat-nat
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State
Tcp 0 0 0.0.0.0: 3306 0.0.0.0: * LISTEN
The above shows that the MySQL service has been started.
2) install the client
Run the following command:
[Root @ test1 local] # rpm-ivh MySQL-client-4.0.23-0.i386.rpm
Warning: MySQL-client-4.0.23-0.i386.rpm: V3 DSA signature: NOKEY, key ID 5072e1f5
Preparing... ######################################## ### [100%]
1: mySQL-client ##################################### ###### [100%]
The installation is complete.
Use the following command to connect to mysql and test whether the connection is successful.
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 @ test1 local] # mysql
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 1 to server version: 4.0.16-standard
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.

4. Several important MySQL Directories
After MySQL is installed, its database files, configuration files, and command files are not installed in the same directory as SQL Server by default. It is very important to understand these directories, especially for Linux beginners, the directory structure of Linux itself is complicated. If you cannot figure out the installation directory of MySQL, you won't be able to learn it in depth.
The following describes these directories.
1. Database directory
/Var/lib/mysql/
2. Configuration File
/Usr/share/mysql (mysql. server command and configuration file)
3. Related commands
/Usr/bin (commands such as mysqladmin mysqldump)
4. Start the script
/Etc/rc. d/init. d/(directory for starting the script file mysql)
5. Change the logon Password
MySQL does not have a password by default. It is self-evident that the password is added after installation.
1. Commands
Usr/bin/mysqladmin-u root password 'new-password'
Format: mysqladmin-u username-p old password New password
2. Example
Example 1: Add a 123456 password to the root user.
Type the following command:
[Root @ test1 local] #/usr/bin/mysqladmin-u root password 123456
Note: because the root account does not have a password at the beginning, the old-p password can be omitted.
3. test whether the modification is successful
1) login without a password
[Root @ test1 local] # mysql
ERROR 1045: Access denied for user: 'root @ localhost' (Using password: NO)
An error is displayed, indicating that the password has been modified.
2) log on with the modified Password
[Root @ test1 local] # mysql-u root-p
Enter password: (Enter the password 123456 after modification)
Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 4 to server version: 4.0.16-standard
Type 'help; 'or' \ H' for help. Type '\ C' to clear the buffer.
Mysql>
Successful!
You can use the mysqladmin command to change the password or the database to change the password.
6. Start and Stop
1. Start
After MySQL is installed, run the following command to start mysql in the/etc/init. d directory.
[Root @ test1 init. d] #/etc/init. d/mysql start
2. Stop
/Usr/bin/mysqladmin-u root-p shutdown
3. Automatic Start
1) Check whether mysql is in the Auto Start List
[Root @ test1 local] #/sbin/chkconfig-list
2) Add MySQL to the startup Service Group of your system.
[Root @ test1 local] #/sbin/chkconfig-add mysql
3) Delete MySQL from the startup Service Group.
[Root @ test1 local] #/sbin/chkconfig-del mysql

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.