Home > Database > Mysql Tutorial > How to install and configure Mysql database under CentOS6.4

How to install and configure Mysql database under CentOS6.4

王林
Release: 2023-06-04 09:57:35
forward
930 people have browsed it

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 easy to install on Windows. Conveniently, if you want to install a database on Linux, the first thing we have to recommend is the mysql database, and the first version of the mysql database was released on the Linux system.

Mysql is a relational database management system developed by the Swedish mysql ab company and currently belongs to Oracle. MySQL is a relational database management system. A relational database stores data in different tables instead of putting all data in one large warehouse, which increases speed and flexibility. The sql language for mysql 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 version and commercial version. Due to its small size, fast speed and low total cost of ownership, especially the characteristics of open source, it is generally used by small and medium-sized enterprises. For website development, MySQL is chosen as the website database. Due to the excellent performance of its community version, it can form a good development environment with PHP and Apache.

To install the mysql database on Linux, you can download the corresponding database file according to your operating system.

mysql5.0 version download address collection:

Here I install the mysql database through yum. If you install it in this way, you can install it with Some services and jar packages related to mysql have been installed for us, so we save a lot of unnecessary trouble! ! !

2. Uninstall the original mysql

Because the mysql database is so popular on Linux, the mainstream Linux system versions currently downloaded are basically integrated The mysql database is inside. 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  // 这个命令就会查看该操作系统上是否已经安装了mysql数据库
Copy after login

If so, we can use the rpm -e command or the rpm -e --nodeps command. Uninstall

[root@xiaoluo ~]# rpm -e mysql  // 普通删除模式
[root@xiaoluo ~]# rpm -e --nodeps mysql  // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
Copy after login

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

3. Install mysql through yum

I install mysql database through yum. 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
Copy after login

You can get the downloadable version information of the mysql database on the yum server: How to install and configure Mysql database under CentOS6.4

Then we can pass Enter the yum install -y mysql-server mysql mysql-devel command to install mysql mysql-server mysql-devel (note: when installing mysql, we do not install the mysql client, which is equivalent to installing the mysql database. We also You need to install the mysql-server server)

[root@xiaoluo ~]# yum install -y mysql-server mysql mysql-deve
Copy after login

After waiting for a while, yum will help us choose the software needed to install the mysql database and other ancillary softwareHow to install and configure Mysql database under CentOS6.4

We found that installing the mysql database through yum saves a lot of unnecessary trouble. When the following results appear, it means that the mysql database has been installed successfully. How to install and configure Mysql database under CentOS6.4
At this time, we can use the following command to view The newly installed version of mysql-server

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

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. At this point our mysql The database installation has been completed.

4. Initialization and related configuration of mysql database

After we install 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

初始化 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 after login

At this time we will see the first time mysql is started The server will prompt a lot of information in the future. 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
停止 mysqld:                       [确定]
正在启动 mysqld:                     [确定]
Copy after login

We are using the mysql database When, the mysqld service must be started first. We can use the chkconfig --list | grep mysqld command to check whether the mysql service starts automatically at boot, such as:

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

We found that the mysqld service did not start automatically at boot. We Of course, you can set it to start up through the chkconfig mysqld on command, so that you don’t have to start it manually every time

[root@xiaoluo ~]# chkconfig mysqld on
[root@xiaoluo ~]# chkconfig --list | grep mysql
mysqld       0:关闭  1:关闭  2:启用  3:启用  4:启用  5:启用  6:关闭
Copy after login

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

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

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

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

此时我们就可以通过 mysql -u root -p 命令来登录我们的mysql数据库了How to install and configure Mysql database under CentOS6.4

五、mysql数据库的主要配置文件

1./etc/my.cnf 这是mysql的主配置文件

我们可以查看一下这个文件的一些信息

[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 after login

2./var/lib/mysql mysql数据库的数据库文件存放位置

我们的mysql数据库的数据库文件通常是存放在了/ver/lib/mysql这个目录下

 [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 4月  6 22:01 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 4月  6 21:59 ib_logfile1
drwx------. 2 mysql mysql   4096 4月  6 21:59 mysql  // 这两个是mysql数据库安装时默认的两个数据库文件
srwxrwxrwx. 1 mysql mysql    0 4月  6 22:01 mysql.sock
drwx------. 2 mysql mysql   4096 4月  6 21:59 test  // 这两个是mysql数据库安装时默认的两个数据库文件
Copy after login

我们可以自己创建一个数据库,来验证一下该数据库文件的存放位置

创建一个我们自己的数据库:
mysql> create database xiaoluo;
query ok, 1 row affected (0.00 sec)

[root@xiaoluo mysql]# ls -l
总用量 20492
-rw-rw----. 1 mysql mysql 10485760 4月  6 22:01 ibdata1
-rw-rw----. 1 mysql mysql 5242880 4月  6 22:01 ib_logfile0
-rw-rw----. 1 mysql mysql 5242880 4月  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 mysql   4096 4月  6 22:15 xiaoluo  // 这个就是我们刚自己创建的xiaoluo数据库
[root@xiaoluo mysql]# cd xiaoluo/
[root@xiaoluo xiaoluo]# ls
db.opt
Copy after login

3./var/log mysql数据库的日志输出存放位置

我们的mysql数据库的一些日志输出存放位置都是在/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 after login

其中mysqld.log 这个文件就是我们存放我们跟mysql数据库进行操作而产生的一些日志信息,通过查看该日志文件,我们可以从中获得很多信息

 因为我们的mysql数据库是可以通过网络访问的,并不是一个单机版数据库,其中使用的协议是 tcp/ip 协议,我们都知道mysql数据库绑定的端口号是 3306 ,所以我们可以通过 netstat -anp 命令来查看一下,linux系统是否在监听 3306 这个端口号:How to install and configure Mysql database under CentOS6.4

The above is the detailed content of How to install and configure Mysql database under CentOS6.4. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template