CentOS6.8 二进制包安装MysqL5.7
MysqL5.7的二进制包可以去官网直接下载,比较慢
这里如果搜索的是source code 就是找源码包了,所以要搜索 linux-generic,搜索出来的就是二进制包了。
我这里是去国内镜像网站下载的,速度快一些。
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.17-linux-glibc2.5-x86_64.tar
#创建运行MysqL的账号 [root@MysqL ~]# useradd MysqL -s /sbin/nologin [root@MysqL ~]# id MysqL uid=1001(MysqL) gid=1001(MysqL) 组=1001(MysqL) #创建MysqL相关目录 [root@MysqL ~]# mkdir -p /data/MysqL/MysqL3306/{conf,data,logs,tmp} [root@MysqL ~]# chown -R MysqL.MysqL /data/MysqL/ #解压MysqL安装文件到/usr/local下 [root@MysqL ~]# tar xf MysqL-5.7.20-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ [root@MysqL ~]# ln -sv /usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64 /usr/local/MysqL "/usr/local/MysqL" -> "/usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64" #创建MysqL配置文件 [root@MysqL ~]# cat /data/MysqL/MysqL3306/conf/my.cnf [client] port = 3306 socket = /tmp/MysqL3306.sock [MysqL] prompt="\\u@\\h [\\d]>" #pager="less -i -n -S" #tee=/opt/MysqL/query.log no-auto-rehash [MysqLd] #misc user = MysqL basedir = /usr/local/MysqL datadir = /data/MysqL/MysqL3306/data port = 3306 socket = /tmp/MysqL3306.sock event_scheduler = 0 tmpdir = /data/MysqL/MysqL3306/tmp #timeout interactive_timeout = 300 wait_timeout = 300 #character set character-set-server = utf8 open_files_limit = 65535 max_connections = 100 max_connect_errors = 100000 lower_case_table_names =1 # explicit_defaults_for_timestamp=1 #symi replication #rpl_semi_sync_master_enabled=1 #rpl_semi_sync_master_timeout=1000 # 1 second #rpl_semi_sync_slave_enabled=1 #logs log-output=file slow_query_log = 1 slow_query_log_file = slow.log log-error = error.log pid-file = MysqL.pid long_query_time = 1 #log-slow-admin-statements = 1 #log-queries-not-using-indexes = 1 log-slow-slave-statements = 1 #binlog #binlog_format = STATEMENT binlog_format = row server-id = 1013306 log-bin = /data/MysqL/MysqL3306/logs/MysqL-bin binlog_cache_size = 1M max_binlog_size = 256M sync_binlog = 0 expire_logs_days = 10 #procedure log_bin_trust_function_creators=1 # gtid-mode = on enforce-gtid-consistency=1 #relay log skip_slave_start = 1 max_relay_log_size = 128M relay_log_purge = 1 relay_log_recovery = 1 relay-log=relay-bin relay-log-index=relay-bin.index log_slave_updates #slave-skip-errors=1032,1053,1062 #skip-grant-tables #buffers & cache table_open_cache = 2048 table_definition_cache = 2048 table_open_cache = 2048 max_heap_table_size = 96M sort_buffer_size = 128K join_buffer_size = 128K thread_cache_size = 200 query_cache_size = 0 query_cache_type = 0 query_cache_limit = 256K query_cache_min_res_unit = 512 thread_stack = 192K tmp_table_size = 96M key_buffer_size = 8M read_buffer_size = 2M read_rnd_buffer_size = 16M bulk_insert_buffer_size = 32M #myisam myisam_sort_buffer_size = 128M myisam_max_sort_file_size = 10G myisam_repair_threads = 1 #innodb innodb_buffer_pool_size = 100M innodb_buffer_pool_instances = 1 innodb_data_file_path = ibdata1:100M:autoextend innodb_flush_log_at_trx_commit = 2 innodb_log_buffer_size = 8M innodb_log_file_size = 100M innodb_log_files_in_group = 3 innodb_max_dirty_pages_pct = 50 innodb_file_per_table = 1 innodb_rollback_on_timeout innodb_status_file = 1 innodb_io_capacity = 2000 transaction_isolation = READ-COMMITTED innodb_flush_method = O_DIRECT loose_tokudb_cache_size=100M loose_tokudb_directio=ON loose_tokudb_fsync_log_period=1000 loose_tokudb_commit_sync=0 #初始化MysqL [root@MysqL ~]# /usr/local/MysqL/bin/MysqLd --defaults-file=/data/MysqL/MysqL3306/conf/my.cnf --initialize #获取初始化生成的密码 [root@MysqL ~]# cat /data/MysqL/MysqL3306/data/error.log | grep password | awk '{print $NF}' H=?ycalZA4.e #启动MysqL [root@MysqL ~]# /usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64/bin/MysqLd --defaults-file=/data/MysqL/MysqL3306/conf/my.cnf & [1] 4596 [root@MysqL ~]# ss -tnl State Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 70 :::3306 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* [root@MysqL ~]# ps aux |grep MysqL MysqL 4596 3.8 17.8 1077724 181116 pts/0 Sl 04:01 0:00 /usr/local/MysqL-5.7.20-linux-glibc2.12-x86_64/bin/MysqLd --defaults-file=/data/MysqL/MysqL3306/conf/my.cnf root 4632 0.0 0.0 112656 972 pts/0 R+ 04:01 0:00 grep --color=auto MysqL #连接到数据库 [root@MysqL ~]# /usr/local/MysqL/bin/MysqL -u root -p -S /tmp/MysqL3306.sock Enter password: #这输入的是上文中获取到的密码 Welcome to the MysqL monitor. Commands end with ; or \g. Your MysqL connection id is 4 Server version: 5.7.20-log Copyright (c) 2000,2017,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; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. #修改root用户的密码为123456 MysqL> alter user user() identified by '123456'; Query OK,0 rows affected (0.00 sec) MysqL> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | MysqL | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) #用新密码重新登陆 [root@MysqL ~]# /usr/local/MysqL/bin/MysqL -u root -p123456 -S /tmp/MysqL3306.sock MysqL: [Warning] Using a password on the command line interface can be insecure. Welcome to the MysqL monitor. Commands end with ; or \g. Your MysqL connection id is 5 Server version: 5.7.20-log MysqL Community Server (GPL) Copyright (c) 2000,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>
关闭MysqL数据库
#通过MysqLadmin接口关闭数据库
[root@MysqL ~]# /usr/local/MysqL/bin/MysqLadmin -u root -p123456 -S /tmp/MysqL3306.sock shutdown
MysqLadmin: [Warning] Using a password on the command line interface can be insecure.
#检查结果[root@MysqL ~]# ss -tnl |grep 3306[root@MysqL ~]# ps aux |grep MysqL |grep -v grep