Installation and configuration of Mysql database under CentOS6.4

If you want to do j2ee development on Linux, you must first build a development environment for j2ee, including the installation of jdk, tomcat, and eclipse (this has been explained in detail in a previous essay on CentOS for Linux learning (7)-- The j2ee environment under CentOS ), if we want to develop web projects, we can of course install a myeclipse to the Linux system. This installation method is exactly the same as installing eclipse, so it is not recorded. With jdk, tomcat, eclipse, we can already We have developed our program, but if we want to do a project, even if it is a small project, it is inseparable from the storage of data! ! ! That's right, we are still missing one of the most important software, which is the database! ! ! If there is no database, our project is simply an illusion, so for the database installation, I wrote this essay specially for installing the mysql database. . . . . .

1. Introduction to MySQL

When it comes to databases, most of us think of relational databases, such as mysql, oracle, sqlserver, etc. These database software are very convenient to install on Windows. If you want to install a database on Linux, we have to recommend mysql first. database, and the first version of the Mysql database was released on Linux systems.

MySQL is a relational database management system developed by the Swedish MySQL AB company and currently belongs to the Oracle company. MySQL is a relational database management system, relational databases keep data in different tables instead of keeping all the data in one big warehouse, which increases speed and improves flexibility. MySQL's SQL language is the most commonly used standardized language for accessing databases. MySQL software adopts a dual authorization policy (this entry "authorization policy"), which is divided into community edition and commercial edition. Due to its small size, fast speed, low total cost of ownership, especially open source The development of the website chooses MySQL as the website database. Due to the excellent performance of its community edition, it can form a good development environment with PHP and Apache.

To install the mysql database on Linux, we can go to its official website to download the rpm package of the mysql database, http://dev.mysql.com/downloads/mysql/5.6.html#downloads , you can download the corresponding database according to your operating system The latest version of the database file is 5.6.10.

Here I use yum to install the mysql database. In this way, some services and jar packages related to mysql can be installed for us, so a lot of unnecessary troubles are saved! ! !

2. Uninstall the original mysql

Because the mysql database is so popular on Linux, the mainstream Linux system versions downloaded at present are basically integrated with the mysql database. We can use the following command to check whether the mysql database has been installed on our 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 will uninstall it through the rpm -e command or the rpm -e --nodeps command

[root@xiaoluo ~]# rpm - e mysql // Ordinary deletion mode 
[root@xiaoluo ~]# rpm -e --nodeps mysql // Force deletion mode, if the above command is used to delete, it will prompt other dependent files, then use this command to force delete it

After the deletion, we can use the rpm -qa | grep mysql command to check whether mysql has been uninstalled successfully! !

3. 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  yum install -y mysql-server mysql mysql-devel  command ( Note: When installing mysql, we do not install the mysql client, which is equivalent to installing the mysql database Now, we also 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 affiliated software

 

 

We found that installing the mysql database through yum saves a lot of unnecessary trouble. When the following result appears, it means that the mysql database installation is successful

 

 

At this point, we can use the following command to check the version of mysql-server that was just installed

 

[root@xiaoluo ~]# rpm -qi mysql-server

 

The mysql-server we installed is not the latest version. If you want to try the latest version, just go to the mysql official website to download the rpm package and install it. So far, our mysql database has been installed.

Four, mysql database initialization and related configuration

我们在安装完mysql数据库以后,会发现会多出一个mysqld的服务,这个就是咱们的数据库服务,我们通过输入 service mysqld start 命令就可以启动我们的mysql服务。

注意:如果我们是第一次启动mysql服务,mysql服务器首先会进行初始化的配置,如:

copy code
[root@xiaoluo ~]# service mysqld start

初始化 MySQL 数据库: 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...
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!

                                                           [确定]
正在启动 mysqld:                                            [确定]
copy code

 

这时我们会看到第一次启动mysql服务器以后会提示非常多的信息,目的就是对mysql数据库进行初始化操作,当我们再次重新启动mysql服务时,就不会提示这么多信息了,如:

 

[root@xiaoluo ~]# service mysqld restart
停止 mysqld:                                             [确定]
正在启动 mysqld:                                          [确定]

 

我们在使用mysql数据库时,都得首先启动mysqld服务,我们可以 通过  chkconfig --list | grep mysqld 命令来查看mysql服务是不是开机自动启动,如:

 

[root@xiaoluo ~]# chkconfig --list | grep mysqld
mysqld             0:关闭    1:关闭    2:关闭    3:关闭    4:关闭    5:关闭    6:关闭

 

我们发现mysqld服务并没有开机自动启动,我们当然可以通过 chkconfig mysqld on 命令来将其设置成开机启动,这样就不用每次都去手动启动了

 

[root@xiaoluo ~]# chkconfig mysqld on
[root@xiaoluo ~]# chkconfig --list | grep mysql
mysqld              0 : off     1 : off     2 : on     3 : on     4 : on     5 : on     6 : off

 

After the mysql database is installed, there will only be one root administrator account, but the root account at this time has not set a password for it. When the mysql service is started for the first time, some initialization work of the database will be performed. In the information, we see this line of information:

 

/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 root account of mysql, not the root account of Linux )

 

[root@xiaoluo ~]# mysqladmin -u root password  ' root ' // Use this command to set the password for the root account to root

 

At this point, we can  log in to our mysql database through the  mysql -u root -p command.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326512401&siteId=291194637