This is the 29th day of my participation in Gwen Challenge

If you want to do J2EE development on Linux, you must first build a good J2EE development environment, including JDK, Tomcat, Eclipse installation, if you want to develop web projects, we can certainly install a MyEclipse to Linux system. This installation method and installation eclipse is exactly the same, there is no record, with JDK, Tomcat, Eclipse we have been able to carry out our program development, but if you want to do a project, even a small project can not do without data storage!! Yes, we still need one of the most important software not installed, that is, the database!! If there is no database, we do the project is simply a dream, so, for the database installation, specifically for the installation of mysql database wrote this essay……

Introduction to mysql

When it comes to databases, we mostly think of relational databases, such as mysql, Oracle, SQLServer and so on. These database software is very convenient to install on Windows. If you want to install a database on Linux, WE have to recommend mysql database first. And the first version of the Mysql database was released on Linux.

MySQL is a relational database management system developed by MySQL AB and currently owned by Oracle. MySQL is a relational database management system. Relational databases keep data in different tables instead of putting all data in one large warehouse, which increases speed and flexibility. MySQL’s SQL language is the most commonly used standardized language for accessing databases. MySQL software adopts the double licensing policy (this entry “licensing policy”), which is divided into community edition and commercial edition. Because of its small size, fast speed, low total cost of ownership, especially the characteristics of open source, the development of small and medium-sized websites choose MySQL as the website database. Because of the excellent performance of the community version, pairing PHP with Apache makes for a good development environment.

On Linux to install the mysql database, we can go to its website to download mysql database RPM package, dev.mysql.com/downloads/m… , you can according to their own operating system to download the corresponding database file, the latest version is 5.6.10.

Here I am through yum to install mysql database, through this way to install, can be related to mysql some services, JAR packages to us, so save a lot of unnecessary trouble!!

Mysql > uninstall mysql

Mysql database is very popular on Linux, so the mainstream Linux system versions downloaded are basically integrated with mysql database. We can check whether mysql database has been installed on our operating system by running the following command

\ [root @ xiaoluo ~ \] # RPM - qa | grep mysql / / this command will check whether the mysql database has been installed on the operating systemCopy the code

RPM -e –nodeps RPM -e –nodeps

[root@xiaoluo ~\]# RPM -e mysql// Common delete mode \[root@xiaoluo ~\]# RPM -e --nodeps mysql// common delete mode \[root@xiaoluo ~\]# RPM -e --nodeps mysql// You can use this command to forcibly delete itCopy the code

On delete after we can through the RPM – qa | grep mysql command to see if mysql have unloaded success!!

Install mysql through yum

I am for the mysql database by means of yum installation, first of all, we can input yum list | grep mysql command to check the mysql database on yum downloadable version:

\[root@xiaoluo ~\]# yum list | grep mysql
Copy the code

Mysql > install mysql on yum server

Yum install -y mysql-server mysql mysql-devel Mysql > install mysql-devel mysql > install mysql-devel mysql > install mysql-devel mysql > install mysql-devel

\[root@xiaoluo ~\]# yum install -y mysql-server mysql mysql-deve
Copy the code

After waiting for some time, YUM will help us select the software we need to install the mysql database and other ancillary software

We found that installing the mysql database through yum saves a lot of unnecessary trouble. When the following result is displayed, the mysql database is successfully installed

In this case, you can run the following command to check the version of mysql-Server

\[root@xiaoluo ~\]# rpm -qi mysql-server
Copy the code

The mysql-Server we installed is not the latest version. If you want to try the latest version, you can download the RPM package from the official website of mysql and install it. So far, our mysql database has been installed.

Mysql database initialization and related configuration

After we install the mysql database, will find many a mysqld service, this is our database services, we can start by typing service mysqld start command our mysql service.

Note: If we start the mysql server for the first time, the mysql server will perform initial configuration, such as:

\[root@xiaoluo ~\]# **service mysqld start** 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... OK Filling help tables... OK To start mysqld at boot time you have to copy support\-files/mysql.server to the right place for your system PLEASE 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\_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 mysql\-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! \[sure] Starting mysqld: \[Sure]Copy the code

When you restart the mysql server for the first time, you will not be prompted with so many messages, such as:

\[root@xiaoluo ~\]# **service mysqld restart** Stop mysqld: \[confirm]Copy the code

When using the mysql database, we all have to start mysqld service first, we can use the chkconfig — list | grep mysqld command to check the mysql service isn’t boot automatically start, such as:

\ [root @ xiaoluo ~ \] # the chkconfig -- list | grep mysqld mysqld 0: close: 1 closed 2: shut down 3: shut down 4: shut down 5: closed 6: closedCopy the code

We found that the mysqld service does not automatically start upon startup. Of course, we can set it to start upon startup by using the chkconfig mysqld on command, so that we do not have to manually start it every time

\ [root @ xiaoluo ~ \] # the chkconfig mysqld on \ [root @ xiaoluo ~ \] # the chkconfig -- list | grep mysql mysqld 0: close: 1 closed 2: enable 3: enabled 4: enable 5: enable 6: disableCopy the code

Mysql > select * from ‘root’ where user ‘root’ = ‘root’ where user ‘root’ = ‘root’;

/usr/bin/mysqladmin -u root password' new-password'// Sets the password for the root accountCopy the code

So we can use this command to set the password of our root account (note: this root account is mysql root account, not Linux root account)

\[root@xiaoluo ~\]# **mysqladmin -u root password** 'root'// Run this command to set the password of account root to rootCopy the code

Mysql -u root -p mysql -u root -p

Mysql database configuration file

/etc/my. CNF this is the main configuration file for mysql

We can take a look at some information about this file

\[root@xiaoluo etc\]# ls my.cnf 
my.cnf  
\[root@xiaoluo etc\]# cat my.cnf 
\[mysqld\]
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 \[mysqld\_safe\]
log\-error=/var/log/mysqld.log
pid\-file\=/var/run/mysqld/mysqld.pid
Copy the code

2./var/lib/mysql Specifies the directory where the mysql database files are stored

Mysql database files are usually stored in the /ver/lib/mysql directory

\[root@xiaoluo ~\]# CD /var/lib/mysql/ \[root@xiaoluo mysql\]# ls -l 20488-rw-rw ----. 1 mysql mysql 10485760 4月 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 4月 6 21:59 mysql SRWXRWXRWX. 1 mysql mysql 0 4月 6 22:01 mysql.sock DRWX \------. 2 mysql mysql 4096 4月 6 21:59 testCopy the code

We can create a database to verify the location of the database files

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 4月 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 4月 6 21:59 mysql srwxrwxrwx. 1 mysql mysql 0 4月 6 22:01 mysql.sock DRWX \------. 2 mysql Mysql 4096 4月 6 21:59 test DRWX \------. 2 mysql 4096 4月 6 22:15 Xiaoluo \[root@xiaoluo mysql\]# cd xiaoluo/ \[root@xiaoluo xiaoluo\]# ls db.optCopy the code

3./var/log Specifies the log output location of the mysql database

Some mysql database logs are stored in /var/log

\[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
anaconda.storage.log  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
Copy the code

The mysqld.log file is the log information generated by our operation with mysql database. By viewing the log file, we can get a lot of information from it

Mysql database is not a stand-alone database. It uses TCP/IP protocol. Mysql database is bound to port 3306, so we can use netstat -anp command to check whether mysql database is connected to port 3306. Whether Linux is listening on port 3306:

As shown above, the Linux system listens on port 3306, which is our mysql database !!!!

This essay records in detail the mysql database installation and basic configuration of the database through yum under CentOS6.4. In the subsequent Linux learning, I will keep recording my experience and experience !!!!

Persistence is victory !!!!!!!!!!