Installation and configuration of Mysql database under CentOS6.5

 

1. 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! !

 

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

 

Three, mysql database initialization and related configuration

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

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

 
[root@xiaoluo ~]# service mysqld start

Initialize 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...
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: [OK]
复制代码

 

At this time, we will see that a lot of information will be prompted after starting the mysql server for the first time. The purpose is to initialize the mysql database. When we restart the mysql service again, it will not prompt 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  check whether the mysql service is automatically started at boot through the chkconfig --list | grep mysqld command, such as:  

 

[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:关闭    1:关闭    2:启用    3:启用    4:启用    5:启用    6:关闭

 

mysql数据库安装完以后只会有一个root管理员账号,但是此时的root账号还并没有为其设置密码,在第一次启动mysql服务时,会进行数据库的一些初始化工作,在输出的一大串信息中,我们看到有这样一行信息 :

 

/usr/bin/mysqladmin -u root password 'new-password'  // 为root账号设置密码

 

所以我们可以通过 该命令来给我们的root账号设置密码(注意这个root账号是mysql的root账号,非Linux的root账号)

 

[root@xiaoluo ~]# mysqladmin -u root password 'root'  // 通过该命令给root账号设置密码为 root

 

此时我们就可以通过 mysql -u root -p 命令来登录我们的mysql数据库了

 

 

四、开放3306端口

[root@xiaoluo ~]# vim /etc/sysconfig/iptables

 

在对应端口位置下面添加如下内容

-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT

保存后重启防火墙

[root@xiaoluo ~]# service iptables restart

 

JAVA技术交流群 532101200

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326641500&siteId=291194637