1. uninstalling the original mysqlmysql database is too popular on Linux, so the mainstream Linux system versions downloaded are basically integrated with the mysql database, you can run the following command to check whether the mysql database has been installed on our operating system [root 1, uninstall the original mysql
Mysql databases are too popular in Linux, so 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 @ hadoop1 ~] # 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 @ hadoop1 ~] # Rpm-e mysql // normal deletion mode [root @ hadoop1 ~] # 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 !!
2. install mysql using 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@hadoop1 ~]# 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@hadoop1 ~]# yum install -y mysql-server mysql mysql-deve
Installing the mysql database using yum saves a lot of unnecessary trouble. when the following result appears, it indicates that the mysql database has been successfully installed.
3. Mysql database initialization and related configuration
After installing the mysql database, you 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:
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 @ hadoop1 ~] # 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 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 @ hadoop1 ~] # Chkconfig mysqld on [root @ hadoop1 ~] # Chkconfig -- list | grep mysqlmysqld 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:
Therefore, 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@hadoop1 ~]# mysqladmin -u root password 'root'
Main configuration file of mysql database
1./Etc/my. cnfThis is the main configuration file of mysql.
We can check some information about this file.
[root@hadoop1 etc]# ls my.cnf my.cnf[root@hadoop1 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/mysqld.pid
2./Var/lib/mysqlDatabase file storage location of the mysql database
The database files of our mysql database are usually stored in the/ver/lib/mysql directory.
[Root @ hadoop1 ~] # Cd/var/lib/mysql/[root @ hadoop1 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: mysql> create database x1; Query OK, 1 row affected (0.00 sec) [root @ hadoop1 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, December 1, April 6/new database [root @ hadoop1 mysql] # cd xiaoluo/[root @ hadoop1 x1] # lsdb. opt
3./Var/logLog output location of the mysql database
Some log output locations of our mysql database are stored in the/var/log directory.
[root@hadoop1 x1]# cd [root@hadoop1 ~]# cd /var/log[root@hadoop1 log]# lsamanda cron maillog-20130331 spice-vdagent.loganaconda.ifcfg.log cron-20130331 mcelog spooleranaconda.log cups messages spooler-20130331anaconda.program.log dirsrv messages-20130331 sssdanaconda.storage.log 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
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 !!!!