Small C's MySQL Learning Notes (1): installation and deployment of MySQL
Personal MySQL study Notes Chapter 1, record the installation process of MySQL under the linux operating system
Operating system version: Centos 6.5
Database version: MySQL 5.6 Universe 5.7
Download the MySQL installation package
Log on to https://www.mysql.com/downloads/
We are going to install the binary package of MySQL this time. Click "MySQL Community Server" on the page to enter the download page.
At the bottom of the page is the latest version currently available for download:
The latest version of MySQL is 8.0. The red box below represents the last version of MySQL5.7/5.6/5.5. Do not want to download the latest version of these versions. Click the fourth option to find other historical versions of MySQL.
If we want to download version 5.7.20 of MySQL, we can click "Archived versions" to open the historical version of the page and follow the operation flow shown below.
II. MySQL installation process
1. Turn off the firewall and selinux
[root@mysql ~] # service iptables stop
[root@mysql ~] # chkconfig iptables off
[root@mysql ~] # chkconfig-- list | grep iptable
Iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
Modify / etc/selinux/config to change the value of selinux to disabled (operating system needs to be rebooted)
[root@mysql ~] # sestatus
SELinux status: disabled
two。 Modify IO scheduling mode
[root@mysql ~] # echo "deadline" > > / sys/block/sda/queue/scheduler
[root@mysql ~] # cat / sys/block/sda/queue/scheduler
Noop anticipatory [deadline] cfq
3. Modify system restrictions
[root@mysql ~] # echo "mysql soft nofile 65536" > > / etc/security/limits.conf
[root@mysql ~] # echo "mysql hard nofile 65536" > > / etc/security/limits.conf
4. Create mysql users and user groups
[root@mysql ~] # groupadd-g 500mysql
[root@mysql] # useradd-u 500-g 500-r-M-s / sbin/nologin mysql
* * useradd parameter description * *
-g: specify the group to which the user belongs
-M: do not automatically create a user's login directory
-n: cancels the establishment of a group with the user name
-r: set up a system account
-u: specify the user id.
5. Create the necessary directories
1) create MySQL's home directory and grant mysql permission
a. Transfer the package to the / usr/local/ directory
[root@mysql ~] # mv mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz / usr/local/
b. Decompression package
[root@mysql ~] # cd / usr/local/
[root@mysql ~] # tar-xvf mysql-5.6.16-linux-glibc2.5-x86_64.tar.gz
c. Create a mysql directory using a soft connection (the main purpose is to facilitate upgrades)
[root@mysql] # ln-s mysql-5.6.16-linux-glibc2.5-x86_64/ mysql/
d. Modify directory permissions
[root@mysql] # chown-R mysql:mysql mysql/
2) create a data directory for MySQL and grant mysql permission
[root@mysql] # mkdir-p / data/mysql
[root@mysql] # chown mysql:mysql-R / data/
6. Configure the my.cnf file in the / etc/ directory
7. Compile and generate the system library using the following command
[root@mysql ~] # cd / usr/local/mysql/bin
1) version 5.6:
[root@mysql] # / mysql_install_db-basedir=/usr/local/mysql/-datadir=/data/mysql/-defaults-file=/etc/my.cnf-user=mysql
2) version 5.7:
[root@mysql] # / mysqld-- defaults-file=/etc/my.cnf-- basedir=/usr/local/mysql-- datadir=/data/mysql/-- user=mysql-- initialize
* * Note: the defaults-file parameter needs to be placed in the first place, otherwise the creation will fail and the following error will appear in the error log:
Unknown variable 'defaults-file=/etc/my.cnf'
Refer to the official document: https://dev.mysql.com/doc/mysql-linuxunix-excerpt/5.7/en/data-directory-initialization-mysqld.html
8. Start the MySQL database
[root@mysql ~] # cd / usr/local/mysql/bin
[root@mysql] #. / mysqld_safe-- defaults-file=/etc/my.cnf &
III. Closure of MySQL
There are two common ways to shut down a database:
1. Use mysqladmin to close
[root@mysql ~] # cd / usr/local/mysql/bin
[root@mysql] #. / mysqladmin-uroot-p shutdown
two。 In case of emergency or for some reason you forget / do not have the root password of the database and cannot close it with mysqladmin, you can use the following methods:
1) find out the process number of the current MySQL
[root@mysql ~] # ps-ef | grep mysql
2) use the kill command kill of the linux operating system
[root@mysql ~] # kill-9 process number
3) check if there are any process residues
[root@mysql ~] # ps-ef | grep mysql