1.下载二进制包mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz;
先查看是否已经创建mysql:mysql :
sudo cat /etc/passwd | grep mysql
cat /etc/group | grep mysql
2.添加组
# groupadd mysql
# useradd -r -g mysql mysql
3.建目录
mkdir /usr/local/mysql
cd mysql
4.
root@xx /usr/local/mysql#
tar zxvf /usr/local/mysql/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
root@xx /usr/local/mysql# cd mysql-5.7.17-linux-glibc2.5-x86_64
root@xx /usr/local/mysql/mysql-5.7.17-linux-glibc2.5-x86_64# cp ./* .. (注意将解压后文件夹内文件全部复制到/local/mysql下)
[root@xx /usr/local/mysql]# rm -rf mysql-5.7.17-linux-glibc2.5-x86_64
ln -sv /usr/local/mysql-5.7.17-linux-glibc2.5-x86_64 /usr/local/mysql
5.输出环境变量、帮助
#vi /etc/profile
add------export PATH=$PATH:/usr/local/mysql/bin
#source /etc/profile
6.
#mkdir /usr/local/mysql/data
#chown mysql.mysql /usr/local/mysql/data
[root@localhost mysql]# mysqld --verbose --help |more 查看更多初始化参数
[root@localhost mysql]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2016-12-21T09:37:13.532770Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2016-12-21T09:37:16.364569Z 0 [Warning] InnoDB: New log files created, LSN=45790
2016-12-21T09:37:16.881727Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2016-12-21T09:37:17.115686Z 0 [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: 0fbca93f-c761-11e6-9409-000c299a8601.
2016-12-21T09:37:17.220886Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2016-12-21T09:37:17.284087Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
初始化成功了。这里说明下,初始化参数我使用了--initialize-insecure,这样不会设置初始化root密码,如果是 --initialize的话,会随机生成一个密码:
7.
设置加密连接
[root@localhost mysql]# /usr/local/mysql/bin/mysql_ssl_rsa_setup
Generating a 2048 bit RSA private key
..........................................................+++
.......+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
...........+++
...........................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
............................................+++
.............................................................+++
writing new private key to 'client-key.pem'
-----
8.复制配置文件和启动脚本
[root@leo mysql]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
[root@leo mysql]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
9、配置如下
[root@leo mysql]# vi /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
server_id=1
socket=/usr/local/mysql/data/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/usr/local/mysql/data/mysql.pid (无此语句出错)
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket=/usr/local/mysql/data/mysql.sock
10、启动、并查看日志
[root@localhost /usr/local/mysql]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
. [确定]
[root@leo ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. [确定]
Starting MySQL.. [确定]
[root@leo ~]# tail -f /usr/local/mysql/data/localhost.localdomain.err
2016-12-21T09:42:48.493804Z 0 [Note] - '::' resolves to '::';
2016-12-21T09:42:48.493834Z 0 [Note] Server socket created on IP: '::'.
2016-12-21T09:42:48.493990Z 0 [Note] InnoDB: Loading buffer pool(s) from /data/mysql/ib_buffer_pool
2016-12-21T09:42:48.496446Z 0 [Note] InnoDB: Buffer pool(s) load completed at 161221 17:42:48
2016-12-21T09:42:48.512719Z 0 [Note] Event Scheduler: Loaded 0 events
2016-12-21T09:42:48.512907Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check.
2016-12-21T09:42:48.512922Z 0 [Note] Beginning of list of non-natively partitioned tables
2016-12-21T09:42:48.529189Z 0 [Note] End of list of non-natively partitioned tables
2016-12-21T09:42:48.529703Z 0 [Note] /usr/local/mysql/bin/mysqld: ready for connections.
Version: '5.7.17' socket: '/data/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL)
11、登录测试
[root@leo mysql]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.17 MySQL Community Server (GPL)
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> grant all privileges ON *.* TO 'root'@'localhost' identified by "mysql123" with grant option; (必须修改密码,不然出错)
设置mysqld开机自启动服务
[root@leo mysql]# chkconfig --add mysqld
[root@leo mysql]# chkconfig mysqld on
[ace@localhost ~]$ usermod -g ace mysql
[ace@localhost ~]$mysql -uroot -p
@原文有几处错误,已更正。
网友评论