MySQL installation and configuration under CentOS

Source: Internet
Author: User

First, MySQL Introduction

When it comes to databases, we mostly think of relational databases, such as MySQL, Oracle, SQL Server, and so on, which are very easy to install on Windows, and if you want to install a database on Linux, I have to recommend MySQL database first. And the first version of the MySQL database is distributed on Linux systems.

MySQL is a relational database management system developed by the Swedish MySQL AB company, currently owned by Oracle Corporation. MySQL is an associated database management system that keeps data in separate tables rather than putting all of the data in a large warehouse, which increases speed and increases flexibility. MySQL's SQL language is the most commonly used standardized language for accessing databases. MySQL software uses a dual licensing policy (this term "authorization policy"), it is divided into community and commercial version, because of its small size, speed, low total cost of ownership, especially the open source of this feature, the general small and medium-sized web site development has chosen MySQL as the site database. Thanks to the performance of its community edition, PHP and Apache make a good development environment.

To install MySQL database on Linux, we can download the MySQL database rpm package on its official website, Http://dev.mysql.com/downloads/mysql/5.6.html#downloads, Everyone can download the corresponding database files according to their operating system, the latest version is 5.6.10.

Here I am the installation of MySQL database through Yum, this way to install, can be related to MySQL some services, jar packages are installed to us, so save a lot of unnecessary trouble!!!

Second, uninstall the original MySQL

Because MySQL database is very popular on Linux, so the mainstream Linux version of the current download basically integrates the MySQL database inside, we can use the following command to see if the MySQL database is installed on our operating system

[Email protected] ~]# Rpm-qa | grep mysql//This command will check if the MySQL database is already installed on the operating system

If there is, we can unload it by RPM-E command or rpm-e--nodeps command.

[[email protected] ~]# rpm-e mysql//normal delete mode [[email protected] ~]# rpm-e--nodeps MySQL//brute force Delete mode, if you use the above command to delete, prompted to have dependent on the other File, the command can be used to forcefully delete the

After the deletion we can pass Rpm-qa | grep mysql command to see if MySQL has been uninstalled successfully!!

Third, the installation of MySQL through Yum

I am using yum to perform MySQL database installation, first we can enter Yum List | grep mysql command to view the downloadable version of the MySQL database available on Yum:

[email protected] ~]# Yum List | grep MySQL

You can get the downloadable version of the MySQL database on the Yum server:

650) this.width=650; "Src=" http://images.cnitblog.com/blog/432441/201304/ 06234702-6db80283f59c4ad1a649f814d9cbd861.jpg "/>

Then we can install the MySQL mysql-server mysql-devel by entering the yum install-y mysql-server mysql mysql-devel command ( Note: When we installed MySQL, we did not install the MySQL client, which is equivalent to installing the MySQL database, we also need to install the Mysql-server server .

[email protected] ~]# yum install-y mysql-server MySQL Mysql-deve

After waiting for some time, Yum will help us choose the software needed to install the MySQL database and some other ancillary software.

650) this.width=650; "Src=" http://images.cnitblog.com/blog/432441/201304/ 06235302-218eb7ac0ae045319426b230c8bd4c1a.jpg "/>

We found that the installation of the MySQL database through the Yum method eliminates a lot of unnecessary hassle, and when the following results occur, the MySQL database installation is successful.

650) this.width=650; "Src=" http://images.cnitblog.com/blog/432441/201304/ 06235745-91b403a8bb32407696f2a007c6a854a3.jpg "/>

At this point we can view the version of the mysql-server that we just installed with the following command

[Email protected] ~]# Rpm-qi mysql-server

We installed the Mysql-server is not the latest version, if you want to try the latest version, then go to the MySQL website to download rpm package installation, so that our MySQL database has been installed.

Iv. initialization of MySQL database and related configuration

After we install the MySQL database, we will find a mysqld service, this is our database service, we can start our MySQL service by entering the service mysqld start command.

Note : If we are starting the MySQL service for the first time, the MySQL server will first initialize the configuration, such as:

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

[[Email protected] ~]# service mysqld start Initialization  MySQL  database:  warning:  The host  ' Xiaoluo '  could not be looked up with resolveip. this probably means that your libc libraries are not 100 %  compatiblewith this binary MySQL version. The MySQL daemon,  mysqld, should worknormally with the exception that host name  Resolving will not work. this means that you should use ip addresses instead of  hostnameswhen specifying mysql privileges ! Installing mysql system tables ... Okfilling help tables ... okto start mysqld at boot time you have to copysupport-files/ Mysql.server to the right place for your systemplease 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 xiaoluo password  ' New-password ' alternatively you can run:/usr /bin/mysql_secure_installationwhich will also give you the option of  Removing the testdatabases and anonymous user created by default.   this isstrongly 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&nbsP;mysql-test-run.plcd /usr/mysql-test ; perl mysql-test-run.plplease report any  problems with the /usr/bin/mysqlbug script!                                                              [OK] is starting  mysqld:                                              [OK]

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

At this point we will see that the first time you start the MySQL server will prompt a lot of information, the purpose is to initialize the MySQL database, when we restart the MySQL service again, will not prompt so much information, such as:

[[Email protected] ~]# service mysqld Restart stop mysqld: [OK] starting mysqld: Determine

When we use MySQL database, we have to start the Mysqld service first, we can check the MySQL service is not started automatically by chkconfig--list | grep mysqld command, such as:

[Email protected] ~]# Chkconfig--list | grep mysqldmysqld 0: Off 1: Off 2: Off 3: Off 4: off 5: off 6: Off

We found that the MYSQLD service did not start automatically, and of course we can set it to boot up with the chkconfig mysqld on command, so you don't have to start it manually every time.

[[email protected] ~]# chkconfig mysqld on[[email protected] ~]# chkconfig--list | grep mysqlmysqld 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off

MySQL database after installation will only have a root administrator account, but at this time the root account has not set a password for it, the first time the MySQL service started, the database will be some initialization work, in the output of a large string of information, we see a line of information:

/usr/bin/mysqladmin-u root password ' new-password '//Set password for root account

So we can use this command to set the password for our root account ( Note : This root account is the root account of MySQL, not the root account of Linux )

[[email protected] ~]# 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 via the mysql-u root-p command.

650) this.width=650; "Src=" http://images.cnitblog.com/blog/432441/201304/07003612- B31a56759e64417c84d85be6dfca5fbb.jpg "/>

V. Major configuration files for MySQL database

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

We can take a look at some information about this file

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

[Email protected] etc]# my.cnf my.cnf[[email protected] etc]# my.cnf [mysqld]datadir=/var/lib/mysqlsocket=/var/lib/ mysql/mysql.sockuser=mysql# disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=[ Mysqld_safe]log-error=/var/log/mysqld.logpid-=/var/run/mysqld/mysqld.pid

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

2. Storage location of database files for/var/lib/mysql MySQL Database

The database files for our MySQL database are usually stored in the/ver/lib/mysql directory.

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

 [[Email protected] ~]# cd /var/lib/mysql/[[email protected] mysql]# ls  -l Total dosage  20488-rw-rw----.  1 mysql mysql 10485760 4 month    6  22:01 IBDATA1-RW-RW----.  1 mysql mysql  5242880 4 Month    6  22:01 IB_LOGFILE0-RW-RW----.  1 mysql mysql  5242880 4 Month    6  21:59 IB_LOGFILE1DRWX------.  2 mysql mysql     4096 4 Month    6 21:59 mysql//  These two are the default two database files that are installed at MySQL database srwxrwxrwx. 1 mysql  Mysql        0 4 Month    6 22:01  mysql.sockdrwx------.  2 mysql mysql     4096 4 Month     6 21:59 test//  These two are the default two database files for MySQL database installation 

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

We can create a database ourselves to verify where the database files are stored

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

Create a database of our own:mysql> create database xiaoluo; query ok, 1 row affected  (0.00 SEC) [[Email protected] mysql]# ls  -l Total dosage  20492-rw-rw----.  1 mysql mysql 10485760 4 month    6  22:01 IBDATA1-RW-RW----.  1 mysql mysql  5242880 4 Month    6  22:01 IB_LOGFILE0-RW-RW----.  1 mysql mysql  5242880 4 Month    6  21:59 IB_LOGFILE1DRWX------.  2 mysql mysql     4096 4 Month    6 21:59 mysqlsrwxrwxrwx. 1 mysql mysql         0 4 month    6 22:01 mysql.sockdrwx------.  2 mysql  mysql     4096 4 Moon    6 21:59 testdrwx------.   2 mysql mysql     4096 4 Month &nbsP;  6 22:15 xiaoluo//  This is the Xiaoluo database we just created [[email protected] mysql]#  cd xiaoluo/[[email protected] xiaoluo]# lsdb.opt

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

3./var/log MySQL database log output storage location

Some of our MySQL database's log output is stored in the/var/log directory

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

[[email protected] xiaoluo]# cd [[email protected] ~]# cd /var/log[[ email protected] log]# lsamanda                 cron            maillog-20130331   spice-vdagent.loganaconda.ifcfg.log    cron-20130331   mcelog              spooleranaconda.log          cups            messages            spooler-20130331anaconda.program.log  dirsrv          messages-20130331  sssdanaconda.storage.log  dmesg           mysqld.log         tallyloganaconda.syslog        dmesg.old      ntpstats            tomcat6anaconda.xlog         dracut.log      piranha            wpa_ supplicant.loganaconda.yum.log      gdm             pm-powersave.log   wtmpaudit                  httpd           ppp                 Xorg.0.logboot.log               ibacm.log      prelink             xorg.0.log.oldbtmp                   lastlog        sa                  Xorg.1.logbtmp-20130401          libvirt        samba               Xorg.2.logcluster                luci            secure              Xorg.9.logConsoleKit             maillog        secure-20130331    yum.log 

650) this.width=650; "alt=" Copy Code "src=" Http://common.cnblogs.com/images/copycode.gif "/>

Which mysqld.log this file is the log information we have to store our operations with the MySQL database, and we can get a lot of information by looking at the log file.

Because our MySQL database is accessible over the network, not a stand-alone database, where the protocol used is the TCP/IP protocol, we all know that the MySQL database binding port number is 3306, so we can through the NETSTAT-ANP command to see if the Linux system is listening on the 3306 port number:

650) this.width=650; "Src=" http://images.cnitblog.com/blog/432441/201304/07004518- A8b1e585e3e546c1a068d2a38d37b535.jpg "/>

As shown above, the Linux system listens on the 3306 port number is our MySQL database!!!!


This article is from "Go far." blog, declined to reprint!

MySQL installation and configuration under CentOS

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.