Installation and configuration of Mysql database under CentOS6.4 _ MySQL

Source: Internet
Author: User
Tags mysql commands dmesg
Reprinted: http: wwwcnblogscomxiaoluo501395377archive201304073003278html modified some mysql to start the j2ee development environment on Linux, centOS6CentOS for jdk, tomcat, and eclipse

I have modified some mysql commands to start the cloud

To develop j2ee on Linux, you must first build a j2ee development environment, including jdk, tomcat, and eclipse installation (this article has explained in detail CentOS (7) of Linux learning-Building a j2ee environment under CentOS ), if you want to develop a web project, you can install a myeclipse program on the Linux system. the installation method is the same as that for installing eclipse, with jdk, tomcat, and eclipse, we can develop our programs. However, if you want to create a project, even small projects cannot be separated from data storage !!! That's right. we have not installed the most important software, that is, the database !!! If we do not have a database, it is just a fantasy to do a project. so, for database installation, I wrote this article specifically for installing the mysql database ......

I. mysql introduction

Speaking of databases, we mostly think of relational databases, such as mysql, oracle, and sqlserver. These database software is very convenient to install on windows. if you want to install a database on Linux, we have to recommend the mysql database first, and the first version of the Mysql database is released on the Linux system.

MySQL is a relational database management system developed by MySQL AB in Sweden and currently belongs to Oracle. MySQL is an associated database management system that stores data in different tables rather than in a large warehouse. this increases the speed and flexibility. The SQL language of MySQL is the most commonly used standard language for accessing databases. MySQL adopts the dual authorization policy (this term "authorization policy"). It is divided into community edition and commercial edition. because of its small size, fast speed, and low total cost of ownership, especially open source code, MySQL is generally used as the website database for the development of small and medium-sized websites. Due to its superior performance, the community edition works with PHP and Apache to form a good development environment.

Install the mysql database on Linux. you can download the rpm Package of the mysql database from its official website.

Here I use yum to install the mysql database. through this method, we can install mysql-related services and jar packages, this saves a lot of unnecessary trouble !!!

II. uninstall the original mysql

Because mysql databases are too popular on Linux, the mainstream Linux system versions currently downloaded are basically integrated with mysql databases, run the following command to check whether the mysql database has been installed on the operating system:

[root @ xiaoluo ~] # rpm -qa | grep mysql // This command will check whether the mysql database has been installed on the operating system
If there is, we uninstall it with rpm -e command or rpm -e --nodeps command.

[root @ xiaoluo ~] # rpm -e mysql // Normal delete mode
[root @ xiaoluo ~] # rpm -e --nodeps mysql // Powerful delete mode. If you are prompted to rely on other files when deleting using the above command, you can use this command to perform a powerful delete.
After deleting, we can use rpm -qa | grep mysql command to see if mysql has been uninstalled successfully! !!

Third, install mysql through yum

I use yum to install the mysql database. First, we can enter the yum list | grep mysql command to view the downloadable version of the mysql database provided on yum:

[root @ xiaoluo ~] # yum list | grep mysql
You can get the downloadable version information of the mysql database on the yum server:

Then we can install mysql mysql-server mysql-devel by entering the command yum install -y mysql-server mysql mysql-devel (We need to install the mysql-server server)

[root @ xiaoluo ~] # yum install -y mysql-server mysql mysql-deve
After waiting for a while, yum will help us choose the software required to install the mysql database and some other attached software

We found that installing the mysql database through the yum method saved a lot of unnecessary trouble. When the following results appear, it means that the mysql database installation was successful / vc / "target =" _ blank "class =" keylink "> vcD4KPHA + CjxpbWcgc3JjPQ ==" "alt =" \ ">

At this point we can check the version of mysql-server just installed by using the following command

[root @ xiaoluo ~] # rpm -qi mysql-server
The mysql-server we installed is not the latest version. If you want to try the latest version, go to the mysql official website to download the rpm package and install it. So far our mysql database has been installed.

Fourth, the mysql database initialization and related configuration

After we install the mysql database, we will find that there will be an extra mysqld service. This is our database service. We can start our mysql service by entering the service mysqld start command.

Note: If this is the first time we have started the mysql service, the mysql server will first perform the initial configuration, such as:

[root @ xiaoluo ~] # service mysqld start

Initialize the MySQL database: WARNING: The host 'xiaoluo' could not be looked up with resolveip.
This probably means that your libc libraries are not 100% compatible
with this binary MySQL version. The MySQL daemon, mysqld, should work
normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MySQL privileges!
Installing MySQL system tables ...
Filling help tables ...

To start mysqld at boot time you have to copy
support-files / mysql.server to the right place for your system

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 xiaoluo password 'new-password'

Alternatively you can run:
/ usr / bin / mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd / usr; / usr / bin / mysqld_safe &

You can test the MySQL daemon with
cd / usr / mysql-test; perl

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

Starting mysqld: [OK]
At this time, we will see a lot of information after starting the mysql server for the first time, the purpose is to initialize the mysql database. When we restart the mysql service again, we will not be prompted so much information, such as:

[root @ xiaoluo ~] # service mysqld restart
Stop mysqld: [OK]
Starting mysqld: [OK]
When we use the mysql database, we have to start the mysqld service first. We can use the chkconfig --list | grep mysqld command to check whether the mysql service starts automatically when it is started, such as:

[root @ xiaoluo ~] # chkconfig --list | grep mysqld
mysqld 0: close 1: close 2: close 3: close 4: close 5: close 6: close
We found that the mysqld service does not start automatically when it is turned on. Of course, we can set it to start by using the chkconfig mysqld on command, so that we do not have to manually start it each time.

[root @ xiaoluo ~] # chkconfig mysqld on
[root @ xiaoluo ~] # chkconfig --list | grep mysql
mysqld 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable
After the mysql database is installed, there will only be a root administrator account, but the root account has not yet been set a password for it. When the mysql service is started for the first time, some initialization of the database will be performed. In the message, we see a line like this:

/ usr / bin / mysqladmin -u root password 'new-password' // Set a password for the root account
So we can use this command to set a password for our root account (note: this root account is the mysql root account, not the Linux root account)

[root @ xiaoluo ~] # mysqladmin -u root password 'root' // Use this command to set the root account password to root
At this point we can log in to our mysql database through the mysql -u root -p command

Five, the main configuration file of the mysql database

1./etc/my.cnf This is the main configuration file for mysql

We can check some information of this file

[root @ xiaoluo etc] # ls my.cnf

[root @ xiaoluo etc] # cat my.cnf
datadir = / var / lib / mysql
socket = / var / lib / mysql / mysql.sock
user = mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links = 0

log-error = / var / log / mysqld.log
pid-file = / var / run / mysqld /
2./var/lib/mysql Database file storage location of the mysql database

The database files of our mysql database are usually stored in the / ver / lib / mysql directory

[root @ xiaoluo ~] # cd / var / lib / mysql /
[root @ xiaoluo mysql] # ls -l
Total dosage 20488
-rw-rw ----. 1 mysql mysql 10485760 April 6 22:01 ibdata1
-rw-rw ----. 1 mysql mysql 5242880 April 6 22:01 ib_logfile0
-rw-rw ----. 1 mysql mysql 5242880 April 6 21:59 ib_logfile1
drwx ------. 2 mysql mysql 4096 April 6 21:59 mysql // These two are the two default database files when the mysql database is installed
srwxrwxrwx. 1 mysql mysql 0 April 6 22:01 mysql.sock
drwx ------. 2 mysql mysql 4096 April 6 21:59 test // These two are the default two database files when the mysql database is installed
We can create a database by ourselves to verify the storage location of the database file

Create our own database:
mysql> create database xiaoluo;
Query OK, 1 row affected (0.00 sec)

[root @ xiaoluo mysql] # ls -l
Total dosage 20492
-rw-rw ----. 1 mysql mysql 10485760 April 6 22:01 ibdata1
-rw-rw ----. 1 mysql mysql 5242880 April 6 22:01 ib_logfile0
-rw-rw ----. 1 mysql mysql 5242880 April 6 21:59 ib_logfile1
drwx ------. 2 mysql mysql 4096 April 6 21:59 mysql
srwxrwxrwx. 1 mysql mysql 0 April 6 22:01 mysql.sock
drwx ------. 2 mysql mysql 4096 April 6 21:59 test
drwx ------. 2 mysql mysql 4096 April 6 22:15 xiaoluo /// This is the xiaoluo database we just created ourselves
[root @ xiaoluo mysql] # cd xiaoluo /
[root @ xiaoluo xiaoluo] # ls
3./var/log storage location of the mysql database log output

Some log output storage locations of our mysql database are in the / var / log directory

[root @ xiaoluo xiaoluo] # cd
[root @ xiaoluo ~] # cd / var / log
[root @ xiaoluo log] # ls
amanda cron maillog-20130331 spice-vdagent.log
anaconda.ifcfg.log cron-20130331 mcelog spooler
anaconda.log cups messages spooler-20130331
anaconda.program.log dirsrv messages-20130331 sssd dmesg mysqld.log tallylog
anaconda.syslog dmesg.old ntpstats tomcat6
anaconda.xlog dracut.log piranha wpa_supplicant.log
anaconda.yum.log gdm pm-powersave.log wtmp
audit httpd ppp Xorg.0.log
boot.log ibacm.log prelink Xorg.0.log.old
btmp lastlog sa Xorg.1.log
btmp-20130401 libvirt samba Xorg.2.log
cluster luci secure Xorg.9.log
ConsoleKit maillog secure-20130331 yum.log
The mysqld.log file is where we store some log information generated by our operations with the mysql database. By viewing this log file, we can get a lot of information from it

Because our mysql database is accessible through the network, not a stand-alone version of the database, the protocol used is tcp / ip protocol, we all know that the port number bound to the mysql database is 3306, so we can use the netstat -anp command Let's see if the Linux system is listening on port 3306:

The result is shown above. The 3306 port number monitored by the Linux system is our mysql database! !! !! !!

After installing mysql, I don't know when I executed the mysqladmin ... command,
This problem occurs when you connect to the database:
Access denied for user "root '@' localhost '(using password: YES)

[root @ localhost ~] # /etc/init.d/mysql stop
Shutting down MySQL ... [Close]
[root @ localhost ~] # mysqld_safe --user = mysql --skip-grant-tables --skip-networking &
[1] 24482
[root @ localhost ~] # 100902 15:09:24 mysqld_safe Logging to '/var/lib/mysql/localhost.localdomain.err'.
100902 15:09:24 mysqld_safe Starting mysqld daemon with databases from / var / lib / mysql

[root @ localhost ~] # mysql -u root mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with; or \ g.
Your MySQL connection id is 1
Server version: 5.1.50 MySQL Community Server (GPL)

Copyright (c) 2000, 2010, Oracle and / or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\ h' for help. Type '\ c' to clear the current input statement.

mysql> select user, host, password from user;
+ ------ + ----------------------- + ----------- +
| user | host | password |
+ ------ + ----------------------- + ----------- +
| root | localhost | ******** |
| root | localhost.localdomain | ******** |
| root | | ******** |
+ ------ + ----------------------- + ----------- +
3 rows in set (0.00 sec)
update mysql.user set password = PASSWORD ('Change to your password here') Where User = 'root'; Modify the password instructions, then launch and enter again
If not, there are two solutions:

After installing Mysql, type in the terminal, mysql
Started successfully, exited, and then entered mysqladmin -u root password XXXXX, an error occurred: mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user' root '@' localhost '(using password: NO)'

If you enter mysql first and then use mysql after successful startup, the following error occurs: Access denied for user '' @ 'localhost' to database 'mysql'

Also, you can lose mysql, and you can lose by typing mysql -u root:
Access denied for user 'root' @ 'localhost' (using password: NO).

The reason is:
An error occurred while updating the ROOT password yesterday
update user set password = '123456' where user = "root" // Write this wrong, the password is not 123456
Should be update user set password = password ('123456') where user = "root"

Specific steps:
Close mysql:
# service mysqld stop
# mysqld_safe --skip-grant-tables (After the command is completed, the terminal may not prompt for the next command. The following command is implemented in the newly opened terminal.)
Start mysql:
# service mysqld start
mysql -u root
mysql> use mysql
mysql> UPDATE user SET Password = PASSWORD ('xxx') WHERE user = 'root';
mysql> flush privileges;
mysql> \ q

This essay details the installation of the mysql database and the basic configuration of the database through yum under CentOS6.4. In the follow-up Linux learning, I will continue to record my experience and experience! !! !! !!

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: 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.