Mysql 5.7.18 源码包安装

3 篇文章 0 订阅

1.用rz上传mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz到/mysql目录下,并解压
[root@LC01 mysql]tar -zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
2.安装相关组件gcc gcc-c++ kernel-devel ncurses-devel bison cmake
[root@LC01 mysql]#yum install gcc gcc-c++ kernel-devel ncurses-devel bison cmake
3.查询mariadb并卸载掉
[root@LC01 mysql]# rpm -qa | grep -i mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@LC01 mysql]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64
4.新建mysql安装目录和数据存放目录
[root@LC01 mysql]# mkdir /usr/local/mysql /mysql/mysqldata
[root@LC01 mysql]# ls -l
total 639124
drwx------ 2 root root 16384 Dec 9 23:52 lost+found
drwxr-xr-x 9 root root 4096 Dec 9 23:58 mysql-5.7.18-linux-glibc2.5-x86_64
-rw-r–r-- 1 root root 654430368 Aug 11 11:52 mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x 2 root root 4096 Dec 10 00:02 mysqldata
5.将解压后的mysql-5.7.18-linux-glibc2.5-x86_64/下的文件mv到/usr/local/mysql/
[root@LC01 mysql]# mv mysql-5.7.18-linux-glibc2.5-x86_64/
/usr/local/mysql/
6.新建mysql组和用户并授权
[root@LC01 mysql]# groupadd mysql
[root@LC01 mysql]# useradd -r -g mysql mysql
[root@LC01 mysql]# chown -R mysql:mysql /mysql/mysqldata/
[root@LC01 mysql]# ls -l
total 639124
drwx------ 2 root root 16384 Dec 9 23:52 lost+found
drwxr-xr-x 2 root root 4096 Dec 10 00:04 mysql-5.7.18-linux-glibc2.5-x86_64
-rw-r–r-- 1 root root 654430368 Aug 11 11:52 mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
drwxr-xr-x 2 mysql mysql 4096 Dec 10 00:02 mysqldata
[root@LC01 mysql]# cd /usr/local/mysql/
[root@LC01 mysql]# ls -l
total 36
drwxr-xr-x 2 mysql mysql 4096 Dec 9 23:58 bin
-rw-r–r-- 1 mysql mysql 17987 Mar 18 2017 COPYING
drwxr-xr-x 2 mysql mysql 55 Dec 9 23:58 docs
drwxr-xr-x 3 mysql mysql 4096 Dec 9 23:57 include
drwxr-xr-x 5 mysql mysql 229 Dec 9 23:58 lib
drwxr-xr-x 4 mysql mysql 30 Dec 9 23:58 man
-rw-r–r-- 1 mysql mysql 2478 Mar 18 2017 README
drwxr-xr-x 28 mysql mysql 4096 Dec 9 23:58 share
drwxr-xr-x 2 mysql mysql 90 Dec 9 23:58 support-files
7.安装Mysql 并记录下密码
[root@LC01 mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/mysql/mysqldata/ --initialize
-bash: ./bin/mysqld: No such file or directory
[root@LC01 mysql]# cd /usr/local/mysql/
[root@LC01 mysql]# ./bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/mysql/mysqldata/ --initialize
2017-12-09T16:05:32.090172Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-12-09T16:05:33.429326Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-12-09T16:05:33.489904Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-12-09T16:05:33.572584Z 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: c953a2bb-dcfa-11e7-9a84-000c295cceff.
2017-12-09T16:05:33.579966Z 0 [Warning] Gtid table is not ready to be used. Table ‘mysql.gtid_executed’ cannot be opened.
2017-12-09T16:05:33.581053Z 1 [Note] A temporary password is generated for root@localhost: 2UJ>+aeetR:#
[root@LC01 mysql]# find .cnf
find: ‘
.cnf’: No such file or directory
[root@LC01 mysql]# ls -l
total 36
drwxr-xr-x 2 mysql mysql 4096 Dec 9 23:58 bin
-rw-r–r-- 1 mysql mysql 17987 Mar 18 2017 COPYING
drwxr-xr-x 2 mysql mysql 55 Dec 9 23:58 docs
drwxr-xr-x 3 mysql mysql 4096 Dec 9 23:57 include
drwxr-xr-x 5 mysql mysql 229 Dec 9 23:58 lib
drwxr-xr-x 4 mysql mysql 30 Dec 9 23:58 man
-rw-r–r-- 1 mysql mysql 2478 Mar 18 2017 README
drwxr-xr-x 28 mysql mysql 4096 Dec 9 23:58 share
drwxr-xr-x 2 mysql mysql 90 Dec 9 23:58 support-files
8.复制mysql服务到/etc/init.d/mysqld
[root@LC01 mysql]# cp -a ./support-files/mysql.server /etc/init.d/mysqld
9.重启mysql服务,但错误,因此要查找到/etc/my.cnf文件
备注:
Centos7.3下安装mysql5.7.21启动时候报错
[root@pvslc508 bin]# systemctl start mysqld.service
Failed to start mysqld.service: Unit not found.
解决方法:系统加载,执行systemctl daemon-reload
[root@pvslc508 bin]# systemctl daemon-reload
[root@LC01 mysql]# systemctl start mysqld.service
Job for mysqld.service failed because the control process exited with error code. See “systemctl status mysqld.service” and “journalctl -xe” for details.
[root@LC01 mysql]# systemctl status mysqld.service -l
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: failed (Result: exit-code) since Sun 2017-12-10 00:09:28 CST; 9s ago
Docs: man:systemd-sysv-generator(8)
Process: 13188 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=1/FAILURE)

Dec 10 00:09:27 LC01 mysqld[13188]: Starting MySQL.my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 2!
Dec 10 00:09:27 LC01 mysqld[13188]: my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Dec 10 00:09:27 LC01 mysqld[13188]: my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 2!
Dec 10 00:09:27 LC01 mysqld[13188]: my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
Dec 10 00:09:27 LC01 mysqld[13188]: Logging to ‘/usr/local/mysql/data/LC01.err’.
Dec 10 00:09:28 LC01 mysqld[13188]: ERROR! The server quit without updating PID file (/usr/local/mysql/data/LC01.pid).
Dec 10 00:09:28 LC01 systemd[1]: mysqld.service: control process exited, code=exited status=1
Dec 10 00:09:28 LC01 systemd[1]: Failed to start LSB: start and stop MySQL.
Dec 10 00:09:28 LC01 systemd[1]: Unit mysqld.service entered failed state.
Dec 10 00:09:28 LC01 systemd[1]: mysqld.service failed.
[root@LC01 mysql]# cat /etc/my.cnf
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /mysql/mysqldata
port = 3306
# server_id = …
socket = /mysql/mysqldata/mysql.sock
character-set-server = utf8
# 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

10.删除默认的/etc/my.cnf文件,并新建/etc/my.cnf
[root@LC01 mysql]# rm -rf /etc/my.cnf
[root@LC01 mysql]# vi /etc/my.cnf
[mysql]

# CLIENT #
port = 3306
socket = /mysql/mysqldata/mysql.sock
default-character-set = utf8

[mysqld]

# GENERAL #
user = mysql
#default-storage-engine = InnoDB
socket = /mysql/mysqldata/mysql.sock
pid-file = /mysql/mysqldata/mysql.pid
character-set-server = utf8

# MyISAM #
key-buffer-size = 32M
#myisam-recover = FORCE,BACKUP

# SAFETY #
max-allowed-packet = 16M
max-connect-errors = 1000000
skip-name-resolve
sql-mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
sysdate-is-now = 1
innodb = FORCE

# DATA STORAGE #
datadir = /mysql/mysqldata/

# BINARY LOGGING #
log-bin = /mysql/mysqldata/mysql-bin
expire-logs-days = 14
sync-binlog = 1
binlog_format = mixed
server-id = 413

# CACHES AND LIMITS #
tmp-table-size = 32M
max-heap-table-size = 32M
query-cache-type = 0
query-cache-size = 0
max-connections = 500
thread-cache-size = 50
open-files-limit = 65535
table-definition-cache = 4096
table-open-cache = 4096

# INNODB #
innodb-flush-method = O_DIRECT
innodb-log-files-in-group = 2
innodb-log-file-size = 512M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table = 1
innodb-buffer-pool-size = 26G

# LOGGING #
log-error = /mysql/mysqldata/mysql-error.log
log-queries-not-using-indexes = 0
slow-query-log = 1
slow-query-log-file = /mysql/mysqldata/mysql-slow.log
~
“/etc/my.cnf” [New] 62L, 1991C written
11.重启mysql服务
[root@LC01 mysql]# systemctl restart mysqld.service
[root@LC01 mysql]# systemctl status mysqld.service
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since Sun 2017-12-10 00:11:35 CST; 5s ago
Docs: man:systemd-sysv-generator(8)
Process: 13382 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mysqld.service
├─13394 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql/mysqldata/ --pid-file=/mysql/mysq…
└─13919 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql/mysqldata --plugin-…

Dec 10 00:11:27 LC01 systemd[1]: Starting LSB: start and stop MySQL…
Dec 10 00:11:28 LC01 mysqld[13382]: Starting MySQL.Logging to ‘/mysql/mysqldata/mysql-error.log’.
Dec 10 00:11:35 LC01 mysqld[13382]: … SUCCESS!
Dec 10 00:11:35 LC01 systemd[1]: Started LSB: start and stop MySQL.
[root@LC01 mysql]# ls -l /mysql/mysqldata/
total 1073212
-rw-r----- 1 mysql mysql 56 Dec 10 00:05 auto.cnf
-rw-r----- 1 mysql mysql 419 Dec 10 00:05 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Dec 10 00:11 ibdata1
-rw-r----- 1 mysql mysql 536870912 Dec 10 00:11 ib_logfile0
-rw-r----- 1 mysql mysql 536870912 Dec 10 00:11 ib_logfile1
-rw-r----- 1 mysql mysql 12582912 Dec 10 00:11 ibtmp1
drwxr-x— 2 mysql mysql 4096 Dec 10 00:05 mysql
-rw-r----- 1 mysql mysql 154 Dec 10 00:11 mysql-bin.000001
-rw-r----- 1 mysql mysql 34 Dec 10 00:11 mysql-bin.index
-rw-r----- 1 mysql mysql 5265 Dec 10 00:11 mysql-error.log
-rw-r----- 1 mysql mysql 6 Dec 10 00:11 mysql.pid
-rw-r----- 1 mysql mysql 193 Dec 10 00:11 mysql-slow.log
srwxrwxrwx 1 mysql mysql 0 Dec 10 00:11 mysql.sock
-rw------- 1 mysql mysql 6 Dec 10 00:11 mysql.sock.lock
drwxr-x— 2 mysql mysql 4096 Dec 10 00:05 performance_schema
drwxr-x— 2 mysql mysql 12288 Dec 10 00:05 sys

[root@LC01 bin]# pwd
/usr/local/mysql/bin
[root@LC01 bin]# bin/mysql -uroot -p
-bash: bin/mysql: No such file or directory
[root@LC01 bin]# cd /usr/local/mysql/
12.登录mysql,使用第7点中的密码登录后修改密码,和授权允许root用户远程访问,并设置权限强制生效。
[root@LC01 mysql]# bin/mysql -uroot -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
[root@LC01 mysql]# 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.18-log

Copyright © 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> set password for ‘root’@localhost = password(‘vssz@dba’);
Query OK, 0 rows affected, 1 warning (0.03 sec)

mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘your_password’ WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye
[root@LC01 mysql]# bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright © 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>
13.当直接输入mysql -uroot -p 提示命令没找到,需要ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@LC01 mysql]# mysql -uroot -p
bash: mysql: command not found…
[root@LC01 mysql]# ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@LC01 mysql]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.18-log MySQL Community Server (GPL)

Copyright © 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;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
±-------------------+
4 rows in set (0.04 sec)

14.让mysql随着系统自动启动
[root@LC01 ~]# systemctl enable mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig mysqld on
[root@LC01 ~]# systemctl daemon-reload
[root@LC01 ~]# systemctl start mysql
[root@LC01 ~]# systemctl restart mysql
[root@LC01 ~]# systemctl status mysql
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since Sun 2017-12-10 00:36:35 CST; 21s ago
Docs: man:systemd-sysv-generator(8)
Process: 14388 ExecStop=/etc/rc.d/init.d/mysqld stop (code=exited, status=0/SUCCESS)
Process: 14415 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mysqld.service
├─14425 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/mysql/mysqldata/ --pid-file=/mysql/mysq…
└─14953 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/mysql/mysqldata --plugin-…

Dec 10 00:36:30 LC01 systemd[1]: Starting LSB: start and stop MySQL…
Dec 10 00:36:35 LC01 mysqld[14415]: Starting MySQL… SUCCESS!
Dec 10 00:36:35 LC01 systemd[1]: Started LSB: start and stop MySQL.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值