Install and configure the Mysql database in centos

Source: Internet
Author: User
Tags dmesg

Install and configure the Mysql database in centos
I. mysql introduction speaking of databases, we mostly think of relational databases, such as mysql, oracle, and sqlserver. These database software is very convenient to install on windows, if you want to install a database on Linux, We have to first recommend the mysql database, and the first version of the Mysql database is released on Linux. 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 !!! 2. Uninstall the original mysql. Because the mysql database is too popular on Linux, the mainstream Linux system versions downloaded are basically integrated with the mysql database, run 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, run the rpm-e command or the rpm-e -- nodeps command to uninstall [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 a file, other dependent files are prompted, you can use this command to forcibly delete it. After deletion, you can run the rpm-qa | grep mysql command to check whether mysql has been uninstalled successfully !! Iii. Install mysql through yum. I install mysql database through yum, first, you can enter the yum list | grep mysql command to view the available mysql database versions on yum: [root @ xiaoluo ~] # Yum list | grep mysql: 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 the mysql database and some other ancillary software, installing the mysql database using yum saves a lot of unnecessary trouble. When the following result is displayed, it indicates that the mysql database has been successfully installed. In this case, we can run the following command, view the mysql-server version you 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, download the rpm package on the mysql official website, so far, our mysql database has been installed. 4. mysql database initialization and related configuration after we install 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 MySQL database: WARNING: The host 'xiaoluo 'cocould not be looked up with resolveip. this probably means that your libc libraries are not 100% compatiblewith this binary MySQL version. the MySQL daemon, mysqld, shocould worknormally with the exception that host name resolving will not work. this means that you shocould use IP addresses instead of hostnameswhen specifying MySQL privile Ges! Installing MySQL system tables... OKFilling help tables... OKTo start mysqld at boot time you have to copysupport-files/mysql. server to the right place for your systemPLEASE 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_installationwhich will also give you the option of removing the testdatabases and anonymous user created by default. this isstronugly recommended for production servers. see the ma Nual 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.plcd/usr/mysql-test; perl mysql-test-run.plPlease 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 as: [root @ xiaoluo ~] # Service mysqld restart stop mysqld: [OK] Starting mysqld: [OK] We have to start mysqld service first when using mysql database, you 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 mysqldmysqld 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 started, of course, we can use the chkconfig mysqld on command to set it to boot, so that we do not need to manually start it every time [root @ xiaoluo ~] # Chkconfig mysqld on [root @ xiaoluo ~] # Chkconfig -- list | grep mysqlmysqld 0: Disable 1: Disable 2: Enable 3: Enable 4: Enable 5: Enable 6: Disable mysql database after installation there will be only one root administrator account, however, at this time, the root account has not set a password for it. When the mysql service is started for the first time, some database initialization work will be performed. In a large string of output information, we can 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 of the root account to root. Now we can use the mysql-u root-p command to log on to our mysql database. v. Main configuration file of 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/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/


2./var/lib/mysql database file storage location our mysql database file is usually stored in the/ver/lib/mysql directory
[Root @ xiaoluo ~] # Cd/var/lib/mysql/[root @ xiaoluo mysql] # ls-l total usage 20488-rw-rw ----. 1 mysql 10485760 April 6 22:01 ibdata1-rw-rw ----. 1 mysql 5242880 April 6 22:01 ib_logfile0-rw-rw ----. 1 mysql 5242880 April 6 21:59 ib_logfile1drwx ------. 2 mysql 4096 21:59 mysql // these two are the default two database files srwxrwxrwx during mysql database installation. 1 mysql 0 April 6 22:01 mysql. sockdrwx ------. 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 of our own: mysql> create database xiaoluo; Query OK, 1 row affected (0.00 sec) [root @ xiaoluo mysql] # ls-l total usage 202.16-rw-rw ----. 1 mysql 10485760 April 6 22:01 ibdata1-rw-rw ----. 1 mysql 5242880 April 6 22:01 ib_logfile0-rw-rw ----. 1 mysql 5242880 April 6 21:59 ib_logfile1drwx ------. 2 mysql 4096 April 6 21:59 mysqlsrwxrwxrwx. 1 mysql 0 April 6 22:01 mysql. sockdrwx ------. 2 mysql 4096 April 6 21:59 testdrwx ------. 2 mysql 4096 22:15 xiaoluo // This is the xiaoluo database we just created [root @ xiaoluo mysql] # cd xiaoluo/[root @ xiaoluo] # lsdb. opt


3./var/log mysql database log output storage location some of our mysql database log output locations are stored in the/var/log directory
[root@xiaoluo xiaoluo]# cd [root@xiaoluo ~]# cd /var/log[root@xiaoluo log]# lsamanda                cron           maillog-20130331   spice-vdagent.loganaconda.ifcfg.log    cron-20130331  mcelog             spooleranaconda.log          cups           messages           spooler-20130331anaconda.program.log  dirsrv         messages-20130331  dmesg          mysqld.log         tallyloganaconda.syslog       dmesg.old      ntpstats           tomcat6anaconda.xlog         dracut.log     piranha            wpa_supplicant.loganaconda.yum.log      gdm            pm-powersave.log   wtmpaudit                 httpd          ppp                Xorg.0.logboot.log              ibacm.log      prelink            Xorg.0.log.oldbtmp                  lastlog        sa                 Xorg.1.logbtmp-20130401         libvirt        samba              Xorg.2.logcluster               luci           secure             Xorg.9.logConsoleKit            maillog        secure-20130331    yum.log


Mysqld. the log file is the log information generated when we operate with the mysql database. By viewing this log file, we can get a lot of information from this because our mysql database is accessible through the network, not a single-host database, where 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 use the netstat-anp command to check whether the Linux system is listening to the port number 3306: The result is as shown above, the port number 3306 listened to by the Linux system is our mysql database !!!!

Related Article

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