Cat/etc/redhat-release #查看系统版本
CentOS Linux release 7.3.1611 (Core)
Uname-i #查看系统位数
x86_64
Uname-r #查看系统内核
3.10.0-514.el7.x86_64
CentOS 7.0 defaults to using firewall as the firewall
Close firewall:
Systemctl Stop Firewalld.service #停止firewall
Systemctl Disable FIREWALLD #禁止firewall开机启动
To turn off SELinux:
Vim/etc/sysconfig/selinux
Change to Selinux=disabled
Set Setenforce 0 #使配置立即生效
1. If you must install MySQL on CentOS 7, you need to uninstall MARIADB, otherwise it will conflict.
2. Execute this command: RPM-QA | grep mariadb
RPM-E mariadb-libs-5.5.44-2.el7.centos.x86_64--nodeps
1, installation CMake
CMake: Since the general Configure compilation method is deprecated from the MySQL5.5 version, the CMake compiler is required to set the compilation parameters for MySQL. such as: installation directory, data storage directory, character encoding, sorting rules, etc.
2. Install dependent packages
Yum-y install gcc gcc-c++ make cmake autoconf automake ncurses-devel bison zlib libgcrypt libtool Bison
Boost: Starting from MySQL 5.7.5 Boost library is required, MySQL source used in C + + Boost Library, requires the installation of boost1.59.0 or above version
Bison:linux down-C + + parser
Ncurses: Character Terminal processing library
Download Boost_1_59_0.tar.gz
wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
Mkdir-p/usr/local/boost/
TAR-ZXVF boost_1_59_0.tar.gz-c/usr/local/boost/
Download mysql-5.7.22.tar.gz
https://dev.mysql.com/downloads/file/?id=476979
Start installing MySQL
Groupadd MySQL
Useradd mysql-g mysql-s/sbin/nologin-m
Or
Useradd-u mysql-m-s/sbin/nologin #-u: Create a group with the same name as the user and add the user to the group
ID MySQL #查看
TAR-ZXVF mysql-5.7.22.tar.gz #解压
CD mysql-5.7.22 #进入目录
CMake \
-dcmake_install_prefix=/usr/local/mysql-5.7.22 \ #安装基础目录 This value can be set when the server starts with the--BASEDIR option
-dmysql_datadir=/usr/local/mysql-5.7.22/data \ #MySQL数据目录的位置 This value can be set when the server starts with the--DATADIR option
-dmysql_unix_addr=/usr/local/mysql-5.7.22/tmp/mysql.sock \ #socket文件路径, default/tmp/mysql.sock This value can be set when the server starts with the--socket option
-ddefault_charset=utf8 \ #指定服务器默认字符集, default Latin1
-DDEFAULT_COLLATION=UTF8_GENERAL_CI \ Specifies the default proofing rules for the server, default Latin1_general_ci
-dwith_extra_charsets=all \ #要包含哪些额外字符集: All: All character sets. This is the default setting complex: Complex character Set none: no additional character set
-denabled_local_infile=1 \ #启用加载本地数据, default off
-dwith_boost=/usr/local/boost #boost库地址
Compile
Mysql-5.7.22.tar.gz compile time consumes a lot of system resources, it is recommended to use more than one core to compile at the same time, otherwise it may fail to compile
#查看服务器cpu数
grep Processor/proc/cpuinfo | Wc-l
2
Make-j 2
echo $? #0代表没有错
Installation
Make install
echo $? #0代表没有错
Ln-s/usr/local/mysql-5.7.22/usr/local/mysql #做软连接
Ls-l/usr/local/mysql #查看软连接
lrwxrwxrwx. 1 root root 9 16:01/usr/local/mysql-/usr/local/mysql-5.7.22
Mkdir-p/usr/local/mysql/data/#数据库存放目录
Mkdir-p/usr/local/mysql/tmp/#mysql. Sock storage Directory
Mkdir-p/usr/local/mysql/log/#错误日志存放目录
Mkdir-p/usr/local/mysql/run/#mysql. PID Generation Storage Directory
Mkdir-p/usr/local/mysql/log/binlog/#mysql二进制日志生成存放目录
Chown-r mysql:mysql/usr/local/mysql/#授权改变mysql安装目录为所属者和所属组为mysql用户
Initializing the database
/usr/local/mysql/bin/mysqld--user=mysql--initialize-insecure--basedir=/usr/local/mysql/--datadir=/usr/local/ mysql/data/
Production of MySQL system database
--initialize indicates a default build password,--initialize-insecure means no password is generated and the password is empty
CENTOS6 Operation:
Cp/usr/local/mysql/support-files/mysql.server/etc/rc.d/init.d/mysqld #把Mysql加入系统启动
chmod 755/etc/init.d/mysqld
Add power-on self-start
Centos7.3 cannot be added to boot with chkconfig
Append MySQL boot service to/etc/rc.local
echo "/etc/init.d/mysqld start" >>/etc/rc.local
Centos7 Operation:
Cp/usr/local/mysql/support-files/mysql.server/usr/lib/systemd/system/mysqld.service #把Mysql加入系统启动
Modify Vim Mysqld.service
#服务的说明
[Unit]
#描述服务
Description=mysql Server
#After是在那个服务后面启动, typically started after network service startup
After=network.target
#服务运行参数的设置
[Service]
User=mysql
Group=mysql
#后台运行的形式
Type=forking
#服务的具体运行命令
Execstart=/usr/local/mysql/support-files/mysql.server start
#ExecStart =/usr/local/mysql/bin/mysqld--defaults-file=/etc/my.cnf
[Install]
Wantedby=multi-user.target
Add power-on self-start
Systemctl Enable Mysqld
View
Systemctl List-unit-files | grep mysqld
Mysqld.service enabled
Change the configuration file
Vi/etc/my.cnf
[Mysqld]
User=mysql
port=3306
Datadir=/usr/local/mysql/data
Socket=/usr/local/mysql/tmp/mysql.sock
Basedir=/usr/local/mysql
Log-error=/usr/local/mysql/log/mysql_err.log #错误日志文件路径
Pid-file=/usr/local/mysql/run/mysql.pid
#禁用主机名解析
Skip-name-resolve
#默认的数据库引擎
Default-storage-engine=innodb
#不区分大小写
Lower_case_table_names= 1
#开启binlog日志功能
Server-id=1
Log-bin=/usr/local/mysql/log/binlog/mysql57-bin
Relay-log=/usr/local/mysql/log/binlog/mysql57-relay-bin
Binlog-cache-size= 4M #设置二进制日志缓存大小
Max_binlog_cache_size= 8M #最大的二进制Cache日志缓冲尺寸
max_binlog_size= 1G #单个二进制日志文件的最大值, default 1G, Max 1G
sync-binlog= 1 #每隔N秒将缓存中的二进制日志记录写回磁盘
binlog_format= Mixed #二进制日志格式 (mixed (mixed, row (line), statement))
expire_logs_days= #二进制日志文件过期时间
Back_log= #指出在MySQL暂时停止响应新请求之前, how many requests in a short time. Default is 50
open_files_limit= 65535 #Mysql能打开文件的最大个数
max_connections= #指定Mysql允许的最大连接进程数
max_connect_errors= #设置每个主机的连接请求异常中断的最大次数
max_allowed_packet= 16M #服务器一次能处理的最大的查询包的值
wait_timeout= #指定一个请求的最大连接时间
Interactive_timeout =8 #连接保持活动的时间
thread_stack= 192k #设置Mysql每个线程的堆大小, the default value is large enough to satisfy normal user operation
max_binlog_size= 1G #单个二进制日志文件的最大值, default 1G, Max 1G
sync-binlog= 1 #每隔N秒将缓存中的二进制日志记录写回磁盘
binlog_format= Mixed #二进制日志格式 (mixed (mixed, row (line), statement))
expire_logs_days= #二进制日志文件过期时间
Back_log= #指出在MySQL暂时停止响应新请求之前, how many requests in a short time. Default is 50
open_files_limit= 65535 #Mysql能打开文件的最大个数
max_connections= #指定Mysql允许的最大连接进程数
max_connect_errors= #设置每个主机的连接请求异常中断的最大次数
max_allowed_packet= 16M #服务器一次能处理的最大的查询包的值
wait_timeout= 28800 #指定一个请求的最大连接时间
Interactive_timeout =28800 #连接保持活动的时间
thread_stack= 192k #设置Mysql每个线程的堆大小, the default value is large enough to satisfy normal user operation
Slow_query_log=on #开启慢查询
Long_query_time= 2 #指定多少秒未返回结果的查询属于慢查询
slow_query_log_file=/usr/local/mysql/log/mysql57-slow.log #指定慢查询日志文件路径
Log-queries-not-using-indexes #记录所有没有使用到索引的查询语句
min_examined_row_limit= #记录那些由于查到了多余1000次而引发的慢查询
Log-slow-admin-statements #记录那些慢的OPTIMIZE Table,analyze TABLE and Alter
Key_buffer_size= 32M #指定用于索引的缓冲区大小, increase it for better index processing performance
Sort_buffer_size= 2M #设置查询排序时所能使用的缓冲区大小, system default size is 2MB
Join_buffer_size= 2M #联合查询操作所能使用的缓冲区大小
Read_buffer_size= 4M #读查询操作所能使用的缓冲区大小
Read_rnd_buffer_size= 16M #设置进行随机读的时候所使用的缓冲区
Bulk_insert_buffer_size= 8M #若经查使用批量插入的特殊语句来插入数据, can adjust parameters to 16MB-32MB, recommended 8MB
Table_open_cache= #设置高速缓存表的数目
Tmp_table_size= 64M #设置内存临时表最大值
Max_heap_table_size= 64M #独立的内存表所允许的最大容量
Query_cache_size= 32M #指定Mysql查询缓冲区的大小
query_cache_limit= 2M #只有小于此设置值的结果才会被缓存
query_cache_min_res_unit= 2k #设置查询缓存分配内存的最小单位
CENTOS6 start MySQL
/etc/init.d/mysqld start
Starting MySQL. success!
Centos7 start MySQL
Systemctl Start Mysqld.service
View process
Ps-ef | grep MySQL
Root 1712 1 0 09:50 pts/0 00:00:00/bin/sh/usr/local/mysql/bin/mysqld_safe--datadir=/usr/local/mysql/data--pid-file=/ Usr/local/mysql/run/mysql.pid
MySQL 2350 1712 09:50 pts/0 00:00:00/usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql--datadir=/usr/local/ Mysql/data--plugin-dir=/usr/local/mysql/lib/plugin--user=mysql--log-error=/usr/local/mysql/log/mysql_err.log-- open-files-limit=65535--pid-file=/usr/local/mysql/run/mysql.pid--socket=/usr/local/mysql/tmp/mysql.sock--port= 320W
Root 2382 1662 0 09:50 pts/0 00:00:00 grep--color=auto MySQL
View ports
NETSTAT-TLUNP | grep MySQL
TCP6 0 0::: 3306:::* LISTEN 2350/mysqld
View the connections that have been established
Netstat-an | grep EST
TCP 0 10.10.16.252:22 10.10.16.10:50954 established #客户端ssh建立连接
Add MySQL to the system environment variable: added in the last row
Vi/etc/profile
Export path= "/usr/local/mysql/bin/: $PATH"
Source/etc/profile #使配置立刻生效
Log in to MySQL
Mysql
First change of password
Set password for ' root ' @ ' localhost ' =password (' mysql57 ');
Quit #退出
Mysql-uroot-p #重新登录
Mysql57
Second change of password
Grant all on . to ' root ' @ ' localhost ' identified by ' mysql123 ';
Flush privileges;
Setting up remote connections to other hosts
Grant all on . to ' root ' @ '% ' identified by ' password ';
Flush privileges;
A different approach
Use MySQL;
Update user set host= "%" where user= "root" limit 1;
Flush privileges;
mysql-5.7.22 Source Installation