Uninstalling, installing, and configuring Mysql Databases in centos

Source: Internet
Author: User

For example, in Windows server, the SQL Server database is installed. in linux, the mysql database is installed, and the first version of the Mysql database is released on Linux.

I. mysql Introduction

MySQL is a relational database management system developed by MySQL AB in Sweden and currently belongs to Oracle. MySQL is an associated database management system that stores data in different tables rather than in a large warehouse. This increases the speed and flexibility. The SQL language of MySQL is the most commonly used standard language for accessing databases. MySQL adopts the dual Authorization Policy (this term "Authorization Policy"). It is divided into community edition and commercial edition. because of its small size, fast speed, and low total cost of ownership, especially open source code, MySQL is generally used as the website database for the development of small and medium-sized websites. Due to its superior performance, the Community edition works with PHP and Apache to form a good development environment.

Install the mysql database on Linux. You can download the rpm package of the mysql database from its official website.

Here I use yum to install the mysql database. Through this method, we can install mysql-related services and jar packages, this saves a lot of unnecessary trouble !!!

Ii. Uninstall the original mysql

Because mysql databases are too popular on Linux, the mainstream Linux system versions currently downloaded are basically integrated with mysql databases, run the following command to check whether the mysql database has been installed on the operating system:

[Root @ xiaoluo ~] # Rpm-qa | grep mysql // This command will check whether the mysql database has been installed on the Operating System

If yes, run the rpm-e command or the rpm-e -- nodeps command to uninstall it.

[Root @ xiaoluo ~] # Rpm-e mysql // normal deletion Mode

[Root @ xiaoluo ~] # Rpm-e -- nodeps mysql // strong deletion mode. If the above command is used to delete other dependent files, you can use this command to forcibly delete them.

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

Iii. Install mysql through yum

I am using yum to install mysql databases. First, we can enter the yum list | grep mysql command to view the downloadable mysql database version on yum:

[Root @ xiaoluo ~] # Yum list | grep mysql

You can get the downloadable version of the mysql database on the yum server:

Then, run the yum install-y mysql-server mysql-devel command to install mysql-server mysql-devel (note: when installing mysql, We have installed the mysql database instead of the mysql client. We also need to install the mysql-server)

[Root @ xiaoluo ~] # Yum install-y mysql-server mysql-deve

After waiting for some time, yum will help us select the software required to install mysql database and other ancillary software.

We found that installing the mysql database using yum saves a lot of unnecessary trouble. When the following results appear, it indicates that the mysql database has been successfully installed.

In this case, run the following command to check the version of the newly installed mysql-server:

[Root @ xiaoluo ~] # Rpm-qi mysql-server

The mysql-server we installed is not the latest version. If you want to try the latest version, download the rpm package on the mysql official website, so far, our mysql database has been installed.

Iv. mysql database initialization and related configuration

After installing the mysql database, we will find 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 Initialization Configuration, for example:

[Root @ xiaoluo ~] # Service mysqld start

Initialize The MySQL database: WARNING: The host 'xiaoluo 'cocould 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, shocould 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

Stronugly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon:

Cd/usr;/usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

Mysql-test-run.pl for cd/usr/mysql-test; perl

Please report any problems with the/usr/bin/mysqlbug script!

[OK]

Starting mysqld: [OK]

At this time, we will see that a lot of information will be prompted after the mysql server is started for the first time. The purpose is to initialize the mysql database. When we restart the mysql service again, so much information will not be prompted, such:

[Root @ xiaoluo ~] # Service mysqld restart

Stop mysqld: [OK]

Starting mysqld: [OK]

When using the mysql database, we have to start the mysqld service first. We can run the chkconfig -- list | grep mysqld command to check whether the mysql service is automatically started upon startup, for example:

[Root @ xiaoluo ~] # Chkconfig -- list | grep mysqld

Mysqld 0: Close 1: Close 2: Close 3: Close 4: Close 5: Close 6: Close

We found that the mysqld service is not automatically started when it is started. Of course, you can use the chkconfig mysqld on command to set it to boot, so that you do not need to start it manually every time.

[Root @ xiaoluo ~] # Chkconfig mysqld on

[Root @ xiaoluo ~] # Chkconfig -- list | grep mysql

Mysqld 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable

After the mysql database is installed, there will be only one root administrator account, but the root account has not set a password for it. When the mysql service is started for the first time, some database initialization will be performed, in a large string of output information, we can see such a 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 to root for the root account

Now we can log on to our mysql database using the mysql-u root-p command.

V. Main configuration files of the mysql database

1./etc/my. cnf this is the main configuration file of mysql.

We can check 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. 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. pid

2./ver/lib/mysql database file storage location

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

[Root @ xiaoluo ~] # Cd/var/lib/mysql/

[Root @ xiaoluo mysql] # ls-l

Total usage 20488

-Rw ----. 1 mysql 10485760 April 6 22:01 ibdata1

-Rw ----. 1 mysql 5242880 April 6 22:01 ib_logfile0

-Rw ----. 1 mysql 5242880 April 6 21:59 ib_logfile1

Drwx ------. 2 mysql 4096 April 6 21:59 mysql // these two are the default two database files during mysql Database Installation

Srwxrwxrwx. 1 mysql 0 April 6 22:01 mysql. sock

Drwx ------. 2 mysql 4096 April 6 21:59 test // these two are the default two database files during mysql Database Installation

We can create a database to verify the storage location of the database file.

Create a database:

Mysql> create database xiaoluo;

Query OK, 1 row affected (0.00 sec)

[Root @ xiaoluo mysql] # ls-l

Total usage 20492

-Rw ----. 1 mysql 10485760 April 6 22:01 ibdata1

-Rw ----. 1 mysql 5242880 April 6 22:01 ib_logfile0

-Rw ----. 1 mysql 5242880 April 6 21:59 ib_logfile1

Drwx ------. 2 mysql 4096 April 6 21:59 mysql

Srwxrwxrwx. 1 mysql 0 April 6 22:01 mysql. sock

Drwx ------. 2 mysql 4096 April 6 21:59 test

Drwx ------. 2 mysql 4096 April 6 22:15 xiaoluo // This is the xiaoluo database we just created

[Root @ xiaoluo mysql] # cd xiaoluo/

[Root @ xiaoluo] # ls

Db. opt

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

Some log output locations of our mysql database are stored in the/var/log directory.

[Root @ 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 message ages 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 TPD 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

The mysqld. log file is the log information generated when we operate on the mysql database. By viewing this log file, we can obtain a lot of information.

Because our mysql database is accessible through the network, it is not a standalone database, and the protocol used is the TCP/IP protocol. We all know that the port number bound to the mysql database is 3306, so we can run the netstat-anp command to check whether the Linux system is listening for the port number 3306:

The result is as shown above. The port number 3306 monitored by Linux is our mysql database !!!!

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.