Database learning II: mysql installation and startup

Keywords: MySQL SQL yum Database

2, mysql installation and startup

1. How to install mysql

1.RPM, Yum: easy to install, fast to install, unable to customize
 2. Binary: it does not need to be installed, can be used after decompression, and cannot be customized
 3. Compile and install: customizable, slow to install.
Before 5.5:. / configure make make install
 After 5.5: cmakegmake
 4. Compile first, then make rpm, make Yum library, and then install yum.
Simple, fast, customizable, relatively complex production time is long
 Enterprises choose installation mode
 Small and medium-sized enterprises: all of the above methods are OK. Operation and maintenance prefer to compile, and dba prefer to choose binary.
Large enterprises: 4

2. mysql installation

First, MySQL5.6.36 Preparation before installation
(1)Clone a template machine (using centos6),Snapshot after clone
(2)IP host name db02
(3)iptables   selinux (Off)
(4)Download good 5.6.36
(5)Install dependency package
     yum  install  -y  ncurses-devel libaio-devel
(6)install cmake
	yum install cmake –y
(7)Create user
    useradd -s /sbin/nologin -M mysql
	id mysql
//2, MySQL download and installation
(0)To create a software download directory:
mkdir -p /server/tools
cd /server/tools/
(1)Download and upload to/server/tools
//Community MySQL Community Server
cd /server/tools
tar xf mysql-5.6.36.tar.gz
cd mysql-5.6.36
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.6.36 \
-DMYSQL_DATADIR=/application/mysql-5.6.36/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.6.36/tmp/mysql.sock \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \

make && make install

//3, Configure and start
(1)Making a soft connection:
[root@centos6-kvm3 mysql-5.6.36]# ln -s /application/mysql-5.6.36/ /application/mysql
(2)Copy profile to/etc:
[root@centos6-kvm3 support-files]# cp my-default.cnf /etc/my.cnf 
(3)Initialize database:
[root@centos6-kvm3 support-files]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data --user=mysql
(4)Create key directories and set permissions:
[root@centos6-kvm3 support-files]# mkdir -p /application/mysql/tmp
[root@centos6-kvm3 support-files]# chown -R mysql.mysql /application/mysql/
(5)Copy startup script to/etc/init.d/mysqld
[root@centos6-kvm3 support-files]# cp mysql.server /etc/init.d/mysqld 
(6)Start database
[root@centos6-kvm3 support-files]# /etc/init.d/mysqld start
[root@centos6-kvm3 support-files]# ps -ef | grep mysql
[root@centos6-kvm3 support-files]# netstat -lntp | grep 3306
(7)Configure environment variables
[root@centos6-kvm3 support-files]# echo 'PATH=/application/mysql/bin/:$PATH'>>/etc/profile
[root@centos6-kvm3 support-files]# tail /etc/profile
[root@centos6-kvm3 support-files]# source /etc/profile
[root@centos6-kvm3 support-files]# echo $PATH
[root@centos6-kvm3 support-files]# mysql
mysql> select user,host,password from mysql.user;

3. How client programs connect to MySQL

Connect strings over the network
mysql -uroot -poldboy123 -h
 Through socket file
mysql -uroot -poldboy123 -S /tmp/mysql.sock

4. SQL layer processing of mysql:

	1. Received "SQL" sent by connection layer
	2. A special module can judge SQL syntax and semantics (SQL statement types: DDL, DCL, DML)
	3. Send different types of statements to special processing interfaces (parsers)
	4. Parsers, parsing SQL into execution plans
	5. Optimizer, will choose "it" the best execution plan to hand over to the executor
	6. Executor, execute execution plan, get the method of how to get data from "disk"
	7. The specialized thread will get the data method and send it to the lower layer (storage engine layer) for further processing.
	8. Verify authorization. The current user has permission to operate on the library or table object.
	9. Query cache.
	10. Record the modification log binlog.
mysql table storage
 1. Data file
   Page (16k by default): the smallest unit of mysql database storage
   Area: composed of consecutive multiple pages
   Segment: a table (partition table) is a segment that contains multiple extents

5. mysql common commands

mysql Login command
-u   user name
-p   Password
mysql -uroot -poldboy123
-h ip
[root@centos6-kvm3 support-files]# mysql -uroot -poldboy123 -h
[root@centos6-kvm3 support-files]# mysql -uroot -poldboy123 -h localhost
mysql -uroot -poldboy123 -h
-P 3308

mysql -uroot -poldboy123 -h -P 3308
[root@centos6-kvm3 support-files]# mysql -uroot -poldboy123 -P 3306
-S /tmp/mysql.sock
[root@centos6-kvm3 support-files]# mysql -uroot -poldboy123 -S /application/mysql/tmp/mysql.sock 
mysql -uroot -poldboy123 -S /application/mysql/tmp/mysql.sock
-e "show variables like 'server_id';"
mysql -uroot -poldboy123  -e "show variables like 'server_id';"
//Change Password:
[root@centos6-kvm3 support-files]# mysqladmin -uroot -p password oldboy123
Enter password: 

6. Clean up infrequently used databases

select user,host from mysql.user;
drop user ''@'db02';
drop user ''@'localhost';
drop user 'root'@'db02';
drop user 'root'@'::1';
select user,host from mysql.user;
drop database test;
show databases;

Posted by cheechm on Mon, 04 May 2020 17:42:10 -0700