【MySQL】第一章:部署

[root@wallet01 ~]# lsb_release -a
LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch
Distributor ID: CentOS
Description:    CentOS release 6.5 (Final)
Release:        6.5
Codename:       Final

[root@wallet01 ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.201   wallet01

[root@wallet01 ~]# useradd mysql
[root@wallet01 ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)

[root@wallet01 ~]# cat >> /etc/security/limits.conf <<EOF
mysql            soft    nproc          2048
mysql            hard    nproc          65535
mysql            soft    nofile         2048
mysql            hard    nofile         65535
EOF

[root@wallet01 ~]# yum install -y libaio
[root@wallet01 ~]# rpm -qa | grep libaio
libaio-0.3.107-10.el6.x86_64

[root@wallet01 ~]# tar zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz -C /usr/local
[root@wallet01 ~]# cd /usr/local
[root@wallet01 local]# ln -s mysql-5.6.43-linux-glibc2.12-x86_64 mysql
[root@wallet01 local]# cd mysql
[root@wallet01 mysql]# chown -R mysql:mysql data
[root@wallet01 mysql]# cd support-files
[root@wallet01 support-files]# cp mysql.server /etc/init.d/mysqld

[root@wallet01 ~]# chkconfig --add mysqld
[root@wallet01 ~]# chkconfig --level 345 mysqld on
[root@wallet01 ~]# chkconfig --list |grep mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@wallet01 ~]# vim /etc/my.cnf 
[mysqld]
port = 3306
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock

character-set-server = utf8  
explicit_defaults_for_timestamp
open-files-limit = 65535
max_allowed_packet = 16M
max_connections = 500
max_connect_errors = 10000
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log = 1
long_query_time = 5
query_cache_type = 0
query_cache_size = 0
key_buffer_size = 32M

default_storage_engine = innodb
transaction-isolation = repeatable-read
innodb_buffer_pool_size = 2G
innodb_buffer_pool_instances = 2
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_log_buffer_size = 16M
innodb_undo_logs= 128
innodb_undo_tablespaces = 3
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_data_file_path = ibdata1:1024M:autoextend

server_id = 201
log_bin = mysql-bin
binlog_format = row
sync_binlog = 1
binlog_cache_size = 16M
max_binlog_cache_size = 32M
max_binlog_size = 128M
expire_logs_days = 7

[mysql]
no-auto-rehash
default-character-set=utf8
socket = /tmp/mysql.sock

[client]
socket = /tmp/mysql.sock

[root@wallet01 ~]# cd /usr/local/mysql
[root@wallet01 mysql]# scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data

[root@wallet01 ~]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/wallet01.err'.
.                                [  OK  ]

[root@wallet01 ~]# service mysqld status
mysqld (pid  3185) is running...

[root@wallet01 ~]# cat /usr/local/mysql/data/wallet01.err
2019-02-12 11:45:52 12533 [Note] Plugin 'FEDERATED' is disabled.
2019-02-12 11:45:52 12533 [Note] InnoDB: Using atomics to ref count buffer pool pages
2019-02-12 11:45:52 12533 [Note] InnoDB: The InnoDB memory heap is disabled
2019-02-12 11:45:52 12533 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-02-12 11:45:52 12533 [Note] InnoDB: Memory barrier is not used
2019-02-12 11:45:52 12533 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-02-12 11:45:52 12533 [Note] InnoDB: Using Linux native AIO
2019-02-12 11:45:52 12533 [Note] InnoDB: Using CPU crc32 instructions
2019-02-12 11:45:52 12533 [Note] InnoDB: Initializing buffer pool, size = 2.0G
2019-02-12 11:45:53 12533 [Note] InnoDB: Completed initialization of buffer pool
2019-02-12 11:45:53 12533 [Note] InnoDB: Opened 3 undo tablespaces
2019-02-12 11:45:53 12533 [Note] InnoDB: Highest supported file format is Barracuda.
2019-02-12 11:45:53 12533 [Note] InnoDB: 128 rollback segment(s) are active.
2019-02-12 11:45:53 12533 [Note] InnoDB: Waiting for purge to start
2019-02-12 11:45:53 12533 [Note] InnoDB: 5.6.43 started; log sequence number 1509016
2019-02-12 11:45:53 12533 [Warning] No existing UUID has been found, 
so we assume that this is the first time that this server has been started. Generating a new UUID: b23f4533-2e78-11e9-91e4-000c296e09c1.
2019-02-12 11:45:53 12533 [Note] Server hostname (bind-address): '*'; port: 3306
2019-02-12 11:45:53 12533 [Note] IPv6 is available.
2019-02-12 11:45:53 12533 [Note]   - '::' resolves to '::';
2019-02-12 11:45:53 12533 [Note] Server socket created on IP: '::'.
2019-02-12 11:45:53 12533 [Note] Event Scheduler: Loaded 0 events
2019-02-12 11:45:53 12533 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.6.43-log'  socket: '/tmp/mysql.sock'  port: 3306  MySQL Community Server (GPL)
 
[root@wallet01 ~]# /usr/local/mysql/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
mysql: unknown option '--connect-expired-password'
Enter current password for root (enter for none): 
mysql: unknown option '--connect-expired-password'
Enter current password for root (enter for none): 
mysql: unknown option '--connect-expired-password'
Unable to connect to the server as root user, giving up.
Cleaning up...

[root@wallet01 ~]# vi /usr/local/mysql/bin/mysql_secure_installation
sub make_config {
  my $password = shift;
  my $esc_pass = basic_single_escape($rootpass);
  write_file($config,
             "# mysql_secure_installation config file",
             "[mysql]",
             "user=root",
             "password='$esc_pass'",
             "connect-expired-password"); --刪除connect-expired-password
}

[root@wallet01 ~]# /usr/local/mysql/bin/mysql_secure_installation        
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Enter current password for root (enter for none): 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Enter current password for root (enter for none): 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
Unable to connect to the server as root user, giving up.

[root@wallet01 ~]# mkdir -p /var/lib/mysql
[root@wallet01 ~]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock

[root@wallet01 ~]# /usr/local/mysql/bin/mysql_secure_installation                      
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
 ... Success!
By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

[root@wallet01 ~]# vim /etc/profile
PATH=$PATH:/usr/local/mysql/bin
[root@wallet01 ~]# source /etc/profile

[root@wallet01 ~]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@wallet01 ~]# ldconfig

[root@wallet01 ~]# mysql -uroot -pabcd.1234 
mysql> select version();
+------------+
| version()  |
+------------+
| 5.6.43-log |
+------------+
1 row in set (0.00 sec)


創建測試數據庫

[root@wallet01 ~]# yum update -y nss curl libcurl
[root@wallet01 ~]# git clone https://github.com/Percona-Lab/tpcc-mysql.git
Initialized empty Git repository in /root/tpcc-mysql/.git/
remote: Enumerating objects: 392, done.
remote: Total 392 (delta 0), reused 0 (delta 0), pack-reused 392
Receiving objects: 100% (392/392), 202.81 KiB | 179 KiB/s, done.
Resolving deltas: 100% (216/216), done.

[root@wallet01 ~]# cd tpcc-mysql/src
[root@wallet01 src]# make
cc -w -O3 -g -I. `mysql_config --include`  -c load.c
cc -w -O3 -g -I. `mysql_config --include`  -c support.c
cc load.o support.o `mysql_config --libs_r` -lrt -o ../tpcc_load
cc -w -O3 -g -I. `mysql_config --include`  -c main.c
cc -w -O3 -g -I. `mysql_config --include`  -c spt_proc.c
cc -w -O3 -g -I. `mysql_config --include`  -c driver.c
cc -w -O3 -g -I. `mysql_config --include`  -c sequence.c
cc -w -O3 -g -I. `mysql_config --include`  -c rthist.c
cc -w -O3 -g -I. `mysql_config --include`  -c sb_percentile.c
cc -w -O3 -g -I. `mysql_config --include`  -c neword.c
cc -w -O3 -g -I. `mysql_config --include`  -c payment.c
cc -w -O3 -g -I. `mysql_config --include`  -c ordstat.c
cc -w -O3 -g -I. `mysql_config --include`  -c delivery.c
cc -w -O3 -g -I. `mysql_config --include`  -c slev.c
cc main.o spt_proc.o driver.o support.o sequence.o rthist.o sb_percentile.o neword.o payment.o ordstat.o delivery.o 
slev.o `mysql_config --libs_r` -lrt -o ../tpcc_start

[root@wallet01 src]# cd ..
[root@wallet01 tpcc-mysql]# ls -l
total 280
-rw-r--r-- 1 root root   1621 Feb 13 10:17 add_fkey_idx.sql
-rw-r--r-- 1 root root    317 Feb 13 10:17 count.sql
-rw-r--r-- 1 root root   3105 Feb 13 10:17 create_table.sql
-rw-r--r-- 1 root root    194 Feb 13 10:17 Dockerfile
-rw-r--r-- 1 root root    763 Feb 13 10:17 drop_cons.sql
-rw-r--r-- 1 root root   1079 Feb 13 10:17 load_multi_schema.sh
-rw-r--r-- 1 root root    573 Feb 13 10:17 load.sh
-rw-r--r-- 1 root root   2302 Feb 13 10:17 README.md
drwxr-xr-x 2 root root   4096 Feb 13 10:17 schema2
drwxr-xr-x 5 root root   4096 Feb 13 10:17 scripts
drwxr-xr-x 2 root root   4096 Feb 13 10:18 src
-rwxr-xr-x 1 root root  68248 Feb 13 10:18 tpcc_load
-rwxr-xr-x 1 root root 171254 Feb 13 10:18 tpcc_start

[root@wallet01 tpcc-mysql]# mysql -uroot -pabcd.1234

mysql> create database tpcc100;
Query OK, 1 row affected (0.00 sec)

mysql> grant all on tpcc100.* to 'tpcc'@'%' identified by 'tpcc';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

[root@wallet01 tpcc-mysql]# mysql -uroot -p tpcc100 < create_table.sql
[root@wallet01 tpcc-mysql]#./tpcc_load -h 192.168.1.201 -d tpcc100 -u tpcc -p "tpcc" -w 100
[root@wallet01 tpcc-mysql]# mysql -uroot -p tpcc100 < add_fkey_idx.sql

[root@wallet01 tpcc-mysql]# mysql -uroot -pabcd.1234
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| tpcc100            |
+--------------------+
4 rows in set (0.32 sec)

mysql> select count(*) from tpcc100.customer;
+----------+
| count(*) |
+----------+
|  1500000 |
+----------+
1 row in set (0.47 sec)




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章