1、 安装环境
[root@MySQL-Server ~]# cat /etc/redhat-release
CentOS release 6.6 (Final)
[root@MySQL-Server ~]# uname -r
2.6.32-504.el6.x86_64
[root@MySQL-Server ~]# uname -m
x86_64
[root@MySQL-Server ~]# uname -n
MySQL-Server
[root@MySQL-Server ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:0C:9C:B9
inet addr:192.168.100.138 Bcast:192.168.100.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe0c:9cb9/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:88828 errors:0 dropped:0 overruns:0 frame:0
TX packets:27430 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:121655584 (116.0 MiB) TX bytes:2978744 (2.8 MiB)
2、 安装cmake
[root@MySQL-Server ~]# tar xvfz cmake-3.5.2.tar.gz -C /usr/local/src/
[root@MySQL-Server ~]# cd /usr/local/src/cmake-3.5.2/
[root@MySQL-Server cmake-3.5.2]# ./bootstrap
[root@MySQL-Server cmake-3.5.2]# gmake && gmake install
[root@MySQL-Server cmake-3.5.2]# cmake --version
cmake version 3.5.2
CMake suite maintained and supported by Kitware (kitware.com/cmake).
3、 安装MySQL
[root@MySQL-Server ~]# yum -y install ncurses-devel bison
[root@MySQL-Server ~]# rpm -qa ncurses-devel bison
bison-2.4.1-5.el6.x86_64
ncurses-devel-5.7-4.20090207.el6.x86_64
[root@MySQL-Server ~]# useradd -c "For Run MySQL Service" -s /sbin/nologin -M mysql
[root@MySQL-Server ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
[root@MySQL-Server ~]# grep "mysql" /etc/passwd
mysql:x:500:500:For Run MySQL Service:/home/mysql:/sbin/nologin
[root@MySQL-Server ~]# mkdir /data/mysql -p
[root@MySQL-Server ~]# ls -ld /data/mysql/
drwxr-xr-x. 2 root root 4096 May 23 09:39 /data/mysql/
[root@MySQL-Server ~]# tar xvfz mysql-5.6.32.tar.gz -C /usr/local/src/
[root@MySQL-Server ~]# cd /usr/local/src/mysql-5.6.32/
[root@MySQL-Server mysql-5.6.32]# cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.32 \
-DMYSQL_DATADIR=/data/mysql \
-DSYSCONFDIR=/etc \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0
[root@MySQL-Server mysql-5.6.32]# make && make install
[root@MySQL-Server mysql-5.6.32]# ln -s /usr/local/mysql-5.6.32/ /usr/local/mysql
[root@MySQL-Server mysql-5.6.32]# ls -ld /usr/local/mysql
lrwxrwxrwx 1 root root 24 May 23 12:56 /usr/local/mysql -> /usr/local/mysql-5.6.32/
[root@MySQL-Server mysql-5.6.32]# chown -R mysql:mysql /data/mysql/
[root@MySQL-Server mysql-5.6.32]# ls -ld /data/mysql/
drwxr-xr-x. 2 mysql mysql 4096 May 23 09:39 /data/mysql/
4、 初始化设置
[root@MySQL-Server mysql-5.7.17]# cd /usr/local/mysql
[root@MySQL-Server mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql/
Installing MySQL system tables...2020-04-28 14:55:57 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-4-28 14:55:57 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.32) starting as process 18962 ...
2020-04-28 14:55:57 18962 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-04-28 14:55:57 18962 [Note] InnoDB: The InnoDB memory heap is disabled
2020-04-28 14:55:57 18962 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-04-28 14:55:57 18962 [Note] InnoDB: Memory barrier is not used
2020-04-28 14:55:57 18962 [Note] InnoDB: Compressed tables use zlib 1.2.3
2020-04-28 14:55:57 18962 [Note] InnoDB: Using CPU crc32 instructions
2020-04-28 14:55:57 18962 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-04-28 14:55:57 18962 [Note] InnoDB: Completed initialization of buffer pool
2020-04-28 14:55:57 18962 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2020-04-28 14:55:57 18962 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2020-04-28 14:55:57 18962 [Note] InnoDB: Database physically writes the file full: wait...
2020-04-28 14:55:57 18962 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2020-04-28 14:55:58 18962 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2020-04-28 14:56:00 18962 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2020-04-28 14:56:00 18962 [Warning] InnoDB: New log files created, LSN=45781
2020-04-28 14:56:00 18962 [Note] InnoDB: Doublewrite buffer not found: creating new
2020-04-28 14:56:01 18962 [Note] InnoDB: Doublewrite buffer created
2020-04-28 14:56:01 18962 [Note] InnoDB: 128 rollback segment(s) are active.
2020-04-28 14:56:01 18962 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-04-28 14:56:01 18962 [Note] InnoDB: Foreign key constraint system tables created
2020-04-28 14:56:01 18962 [Note] InnoDB: Creating tablespace and datafile system tables.
2020-04-28 14:56:01 18962 [Note] InnoDB: Tablespace and datafile system tables created.
2020-04-28 14:56:01 18962 [Note] InnoDB: Waiting for purge to start
2020-04-28 14:56:01 18962 [Note] InnoDB: 5.6.32 started; log sequence number 0
2020-04-28 14:56:02 18962 [Note] Binlog end
2020-04-28 14:56:02 18962 [Note] InnoDB: FTS optimize thread exiting.
2020-04-28 14:56:02 18962 [Note] InnoDB: Starting shutdown...
2020-04-28 14:56:03 18962 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK
Filling help tables...2020-04-28 14:56:04 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-04-28 14:56:04 0 [Note] /usr/local/mysql/bin/mysqld (mysqld 5.6.32) starting as process 18985 ...
2020-04-28 14:56:04 18985 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-04-28 14:56:04 18985 [Note] InnoDB: The InnoDB memory heap is disabled
2020-04-28 14:56:04 18985 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-04-28 14:56:04 18985 [Note] InnoDB: Memory barrier is not used
2020-04-28 14:56:04 18985 [Note] InnoDB: Compressed tables use zlib 1.2.3
2020-04-28 14:56:04 18985 [Note] InnoDB: Using CPU crc32 instructions
2020-04-28 14:56:04 18985 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-04-28 14:56:04 18985 [Note] InnoDB: Completed initialization of buffer pool
2020-04-28 14:56:04 18985 [Note] InnoDB: Highest supported file format is Barracuda.
2020-04-28 14:56:04 18985 [Note] InnoDB: 128 rollback segment(s) are active.
2020-04-28 14:56:04 18985 [Note] InnoDB: Waiting for purge to start
2020-04-28 14:56:04 18985 [Note] InnoDB: 5.6.32 started; log sequence number 1625977
2020-04-28 14:56:04 18985 [Note] Binlog end
2020-04-28 14:56:04 18985 [Note] InnoDB: FTS optimize thread exiting.
2020-04-28 14:56:04 18985 [Note] InnoDB: Starting shutdown...
2020-04-28 14:56:05 18985 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'
/usr/local/mysql/bin/mysqladmin -u root -h MySQL-Server password 'new-password'
Alternatively you can run:
/usr/local/mysql/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd . ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems at http://bugs.mysql.com/
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
WARNING: Found existing config file /usr/local/mysql/my.cnf on the system.
Because this file might be in use, it was not replaced,
but was used in bootstrap (unless you used --defaults-file)
and when you later start the server.
The new default config file was created as /usr/local/mysql/my-new.cnf,
please compare it with your file and take the changes you need.
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server
[root@MySQL-Server mysql]# /bin/cp -a /usr/local/src/mysql-5.6.32/support-files/my-default.cnf /etc/my.cnf
[root@MySQL-Server mysql]# cp -a /usr/local/src/mysql-5.6.32/support-files/mysql.server /etc/init.d/mysqld
[root@MySQL-Server mysql]# chmod +x /etc/init.d/mysqld
[root@MySQL-Server mysql]# ls -l /etc/init.d/mysqld
-rwxr-xr-x. 1 root root 10905 May 23 14:05 /etc/init.d/mysqld
[root@MySQL-Server mysql]# echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
[root@MySQL-Server mysql]# tail -1 /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@MySQL-Server mysql]# source /etc/profile
[root@MySQL-Server mysql]# which mysql
/usr/local/mysql/bin/mysql
[root@MySQL-Server mysql]# vim /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
socket = /tmp/mysql.sock
character-set-server = utf8
collation-server = utf8_unicode_ci
log-error = /data/mysql/mysql_error.log
pid-file = /data/mysql/mysql.pid
skip-name-resolve
skip-external-locking
innodb_data_file_path = ibdata1:10M:autoextend:max:10G
max_connections = 3000
back_log = 256
[mysqldump]
quick
max_allowed_packet = 64M
[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 256M
read_buffer = 2M
write_buffer = 2M
[root@MySQL-Server mysql]# /etc/init.d/mysqld start
Starting MySQL........ SUCCESS!
[root@MySQL-Server mysql]# netstat -tnlup|grep "mysqld"|grep -v "grep"
tcp 0 0 :::3306 :::* LISTEN 19243/mysqld
[root@MySQL-Server mysql]# ps -ef|grep "mysqld"|grep -v "grep"
root 19074 1 0 15:01 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/data/mysql/MySQL-Server.pid
mysql 19243 19074 6 15:01 pts/1 00:00:04 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql/MySQL-Server.err --pid-file=/data/mysql/MySQL-Server.pid --socket=/tmp/mysql.sock --port=3306
[root@MySQL-Server mysql]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 19243 mysql 10u IPv6 126412 0t0 TCP *:mysql (LISTEN)
[root@MySQL-Server mysql]# chkconfig --level 3 mysqld on
[root@MySQL-Server mysql]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5、 安全优化设置
[root@MySQL-Server mysql]# mysqladmin -uroot password "axbc1kof"
Warning: Using a password on the command line interface can be insecure.
[root@MySQL-Server mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.32 Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.16 sec)
mysql> drop database test;
Query OK, 0 rows affected (0.30 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)
mysql> select user,host,password from mysql.user;
+------+--------------+-------------------------------------------+
| user | host | password |
+------+--------------+-------------------------------------------+
| root | localhost | *63C053DE068F3E8F1E9D13A8D8C9C124E4D34264 |
| root | mysql-server | |
| root | 127.0.0.1 | |
| root | ::1 | |
| | localhost | |
| | mysql-server | |
+------+--------------+-------------------------------------------+
6 rows in set (0.01 sec)
mysql> drop user 'root'@'mysql-server';
Query OK, 0 rows affected (0.09 sec)
mysql> drop user 'root'@'::1';
Query OK, 0 rows affected (0.01 sec)
mysql> drop user ''@'localhost';
Query OK, 0 rows affected (0.04 sec)
mysql> drop user ''@'mysql-server';
Query OK, 0 rows affected (0.00 sec)
mysql> update mysql.user set password=password('axbc1kof') where user='root' and host='127.0.0.1';
Query OK, 1 row affected (0.22 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select user,host,password from mysql.user;
+------+-----------+-------------------------------------------+
| user | host | password |
+------+-----------+-------------------------------------------+
| root | localhost | *63C053DE068F3E8F1E9D13A8D8C9C124E4D34264 |
| root | 127.0.0.1 | *63C053DE068F3E8F1E9D13A8D8C9C124E4D34264 |
+------+-----------+-------------------------------------------+
2 rows in set (0.03 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.14 sec)
mysql> exit
Bye
发表评论