Centos 7.x 系安装 mysql-community-common-5.7.13-1.el7.x86_64.rpm
1、修改主机名称 (修改主机名永久生效)[root@localhost ~]# hostnamectl set-hostname OA-TS-DB-test[root@OA-TS-DB-test ~]# hostnameOA-TS-DB-test[root@OA-TS-DB-test ~]# uname -aLinux instance-y514l7ol 3.10.0-693.11.1.el7.x
·
1、修改主机名称 (修改主机名永久生效)
[root@localhost ~]# hostnamectl set-hostname OA-TS-DB-test
[root@OA-TS-DB-test ~]# hostname
OA-TS-DB-test
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-common-5.7.13-1.el7.x86_64.rpm
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-libs-5.7.13-1.el7.x86_64.rpm
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-client-5.7.13-1.el7.x86_64.rpm
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-server-5.7.13-1.el7.x86_64.rpm
3、创建MySQL自定义MySQL 目录文件
[root@OA-TS-DB-test src]# mkdir /data/mysqldata/data3306 -p
[root@OA-TS-DB-test src]# chown -R mysql.mysql /data/mysqldata/data3306/
4、配置my.cnf 配置文件
[root@OA-TS-DB-test src]# cat << EOF > /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysqldata/data3306
pid-file = /data/mysqldata/data3306/mysql.pid
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8'
character-set-server = utf8
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysqldata/data3306/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysqldata/data3306/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 200M
innodb_log_file_size = 320M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
5、MySQL 数据库初始化(不推荐)
第一种:生成密码 cat /var/log/mysqld.log ##竟然没有密码,好奇怪~~
mysqld --initialize --user=mysql
第二种:没有密码(推荐)
mysqld --initialize-insecure --user=mysql
解决方法:
[root@OA-TS-DB-test src]# yum install -y libaio
7、登录MySQL 5.7.13
[root@OA-TS-DB-test data3306]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13-log 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.13-log |
+------------+
1 row in set (0.00 sec)
mysql> select user,host,authentication_string,plugin from mysql.user;
+-----------+-----------+-------------------------------------------+-----------------------+
| user | host | authentication_string | plugin |
+-----------+-----------+-------------------------------------------+-----------------------+
| root | localhost | | mysql_native_password |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
+-----------+-----------+-------------------------------------------+-----------------------+
2 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=password("Tongyuan-DB2018%") where User='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> select user,host,authentication_string,plugin from mysql.user;
+-----------+-----------+-------------------------------------------+-----------------------+
| user | host | authentication_string | plugin |
+-----------+-----------+-------------------------------------------+-----------------------+
| root | localhost | *D0E1BA1F955BD0963E9A1F29A1139C7C08EEAF48 | mysql_native_password |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
+-----------+-----------+-------------------------------------------+-----------------------+
2 rows in set (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
[root@localhost ~]# hostnamectl set-hostname OA-TS-DB-test
[root@OA-TS-DB-test ~]# hostname
OA-TS-DB-test
[root@OA-TS-DB-test ~]# uname -a
Linux instance-y514l7ol 3.10.0-693.11.1.el7.x86_64 #1 SMP Mon Dec 4 23:52:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
##这里注意内核的版本信息
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-common-5.7.13-1.el7.x86_64.rpm
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-libs-5.7.13-1.el7.x86_64.rpm
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-client-5.7.13-1.el7.x86_64.rpm
[root@OA-TS-DB-test src]# rpm -ivh --nodeps --force mysql-community-server-5.7.13-1.el7.x86_64.rpm
3、创建MySQL自定义MySQL 目录文件
[root@OA-TS-DB-test src]# mkdir /data/mysqldata/data3306 -p
[root@OA-TS-DB-test src]# chown -R mysql.mysql /data/mysqldata/data3306/
4、配置my.cnf 配置文件
[root@OA-TS-DB-test src]# cat << EOF > /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8
[mysqld]
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/mysql
datadir = /data/mysqldata/data3306
pid-file = /data/mysqldata/data3306/mysql.pid
bind-address = 0.0.0.0
server-id = 1
init-connect = 'SET NAMES utf8'
character-set-server = utf8
#skip-name-resolve
#skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /data/mysqldata/data3306/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /data/mysqldata/data3306/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
lower_case_table_names = 1
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_file_format = Barracuda
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 200M
innodb_log_file_size = 320M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
5、MySQL 数据库初始化(不推荐)
第一种:生成密码 cat /var/log/mysqld.log ##竟然没有密码,好奇怪~~
mysqld --initialize --user=mysql
第二种:没有密码(推荐)
mysqld --initialize-insecure --user=mysql
systemctl start mysqld
解决方法:
[root@OA-TS-DB-test src]# yum install -y libaio
7、登录MySQL 5.7.13
[root@OA-TS-DB-test data3306]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.13-log 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> select version();
+------------+
| version() |
+------------+
| 5.7.13-log |
+------------+
1 row in set (0.00 sec)
mysql> select user,host,authentication_string,plugin from mysql.user;
+-----------+-----------+-------------------------------------------+-----------------------+
| user | host | authentication_string | plugin |
+-----------+-----------+-------------------------------------------+-----------------------+
| root | localhost | | mysql_native_password |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
+-----------+-----------+-------------------------------------------+-----------------------+
2 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=password("Tongyuan-DB2018%") where User='root' and host='localhost';
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> select user,host,authentication_string,plugin from mysql.user;
+-----------+-----------+-------------------------------------------+-----------------------+
| user | host | authentication_string | plugin |
+-----------+-----------+-------------------------------------------+-----------------------+
| root | localhost | *D0E1BA1F955BD0963E9A1F29A1139C7C08EEAF48 | mysql_native_password |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password |
+-----------+-----------+-------------------------------------------+-----------------------+
2 rows in set (0.00 sec)
###授权账号
mysql> grant all on tejian.* to tejian_guest@"%" identified by 'Tongyuan_guest2018%';Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql>
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
更多推荐
已为社区贡献2条内容
所有评论(0)