服务器 | 软件版本 | 服务器地址 | 项目位置 |
---|---|---|---|
CentOS7 | 5.7.19 | X | /usr/local/program/mysql |
配置位置 | 数据位置 | 端口 | 账号/密码 |
---|---|---|---|
/etc/my.conf和/usr/local/program/mysql/my.conf | /data/mysql | 3306 | root/root |
##下载
##解压并改名
[root@localhost program]# tar zxf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
[root@localhost program]# mv mysql-5.7.19-linux-glibc2.12-x86_64 mysql
##创建储存目录
[root@localhost program]# cd /data/
[root@localhost data]# ls
mongodb
[root@localhost data]# mkdir mysql
##创建角色组
[root@localhost data]# groupadd mysql
[root@localhost data]# useradd -r -s /sbin/nologin -g mysql mysql -d /usr/local/program/mysql
[root@localhost data]# chown -R mysql .
[root@localhost data]# chgrp -R mysql .
[root@localhost data]# chown -R mysql /data/mysql
[root@localhost data]# chgrp -R mysql /data/mysql
[root@localhost data]# yum -y install numactl
##安装numactl避免后面的报错
##配置参数
[root@localhost data]# cd /usr/local/program/mysql
[root@localhost mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/usr/local/program/mysql --datadir=/data/mysql/
2018-12-07T03:27:53.377092Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-07T03:27:53.568202Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-07T03:27:53.599225Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-07T03:27:53.661075Z 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: 150ee14b-f9d0-11e8-ac4c-000c298fc204.
2018-12-07T03:27:53.661956Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-07T03:27:53.662545Z 1 [Note] A temporary password is generated for root@localhost: 8k?7*D!u#MQ=
##这里的 8k?7*D!u#MQ= 是默认登录密码
[root@localhost mysql]# ./bin/mysql_ssl_rsa_setup --datadir=/data/mysql/
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'
-----
##在mysql根目录下创建配置文件
[root@localhost mysql]# vim my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES # 一般配置选项
basedir = /usr/local/program/mysql #需修改
datadir = /data/mysql #需修改
port = 3306
socket = /tmp/mysqld.sock
character-set-server=utf8
back_log = 300
max_connections = 3000
max_connect_errors = 50
table_open_cache = 4096
max_allowed_packet = 32M
#binlog_cache_size = 4M
max_heap_table_size = 128M
read_rnd_buffer_size = 16M
sort_buffer_size = 16M
join_buffer_size = 16M
thread_cache_size = 16
query_cache_size = 128M
query_cache_limit = 4M
ft_min_word_len = 8
thread_stack = 512K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 128M
#log-bin=mysql-bin
long_query_time = 6
server_id=1
innodb_buffer_pool_size = 1G
innodb_thread_concurrency = 16
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = on
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
default-character-set=utf8
safe-updates
[myisamchk]
key_buffer = 16M
sort_buffer_size = 16M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
##修改启动文件
[root@localhost mysql]# vim ./support-files/mysql.server
basedir=/usr/local/program/mysql
datadir=/data/mysql
[root@localhost mysql]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# cp my.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
##设置权限
[root@localhost tmp]# cd /tmp/
[root@localhost tmp]# mkdir mysqld
[root@localhost tmp]# chown -R mysql mysqld
[root@localhost tmp]# chgrp -R mysql mysqld
##启动
[root@localhost tmp]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql/localhost.localdomain.err'.
... SUCCESS!
##登录改配置
[root@localhost tmp]# cd /usr/local/program/mysql/bin/
[root@localhost bin]# ./mysql -uroot -p
Enter password: 8k?7*D!u#MQ= (这里是隐藏的)
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
####因为找不到错在哪,怀疑权限问题,所以把下面的话挨着执行了一遍
chown -R mysql /data/mysql
chgrp -R mysql /data/mysql
chown -R mysql /tmp
chgrp -R mysql /tmp
chown -R mysql /usr/local/program/mysql
chgrp -R mysql /usr/local/program/mysql
chown -R mysql /data/mysql .
chgrp -R mysql /data/mysql .
chown -R mysql /tmp .
chgrp -R mysql /tmp .
chown -R mysql /usr/local/program/mysql .
chgrp -R mysql /usr/local/program/mysql .
##然后 ojbk
[root@localhost bin]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!
[root@localhost bin]# ./mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19
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>
##配置环境变量
[root@localhost bin]# vim /etc/profile
export MYSQL_HOME=/usr/local/program/mysql
export PATH=$MYSQL_HOME/bin:$PATH
[root@localhost bin]# source /etc/profile
##配置开机自启
[root@localhost bin]# chmod 755 /etc/init.d/mysqld
[root@localhost bin]# chkconfig --add mysqld
[root@localhost bin]# chkconfig --level 345 mysqld on
##修改密码,到此安装的步骤就全ok
mysql> set password for root@localhost = password('root');
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> exit
[root@localhost ~]# mysql -uroot -proot
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 4
Server version: 5.7.19 MySQL Community Server (GPL)
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>