进入到mysql官网下载自己对应版本的mysql,
下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
我这里下载mysql-5.7.29-linux-glibc2.12-x86_64.tar版本
将下载好的源码压缩包上传至:/usr/local/mysql
也可以进入linux后用命令下载
[root@zyq mysql]# wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.29-linux-glibc2.12-x86_64.tar
安装前,我们可以检测系统是否自带安装 MySQL:
[root@zyq mysql]# rpm -qa | grep mysql
如有,类似 mysql-libs-5.1.52-1.el6_0.1.x86_64
那可以选择进行卸载:
rpm -e mysql-libs-5.1.52-1.el6_0.1.x86_64 // 普通删除模式
rpm -e --nodeps mysql-libs-5.1.52-1.el6_0.1.x86_64 // 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
检查否存在 mariadb 数据库,如有,卸载之,卸载同上
[root@zyq mysql]# rpm -qa | grep mariadb
如有,类似mariadb-libs-5.5.56-2.el7.x86_64
则 卸载rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64
安装源文件版本:mysql-5.7.29-linux-glibc2.12-x86_64.tar
进入安装包 cd /usr/local/mysql
解压源码文件,并重新命名mysql-5.7
[root@zyq mysql]# ll
总用量 1048512
drwxr-xr-x. 9 root root 129 2月 21 21:30 mysql-5.7.29-linux-glibc2.12-x86_64
-rw-------. 1 root root 650215424 2月 21 21:34 mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@zyq mysql]# mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql-5.7
[root@zyq mysql]# ll
总用量 649172
drwxr-xr-x. 9 root root 129 2月 21 21:30 mysql-5.7
-rw-r--r--. 1 root root 664749587 2月 21 16:55 mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
创建数据文件mkdir data
[root@zyq mysql]# mkdir data
[root@zyq mysql]# ll
总用量 649172
drwxr-xr-x. 2 root root 6 2月 21 21:36 data
drwxr-xr-x. 9 root root 129 2月 21 21:30 mysql-5.7
-rw-r--r--. 1 root root 664749587 2月 21 16:55 mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
[root@zyq mysql]#
检查mysql组和用户是否存在,如无创建在这里插入代码片
[root@zyq mysql]# cat /etc/group | grep mysql
#类似
mysql:x:490:
[root@zyq mysql]# cat /etc/passwd | grep mysql
#类似
mysql:x:496:490::/home/mysql:/bin/bash
以上为存在的情况,如无,执行添加命令:groupadd mysql
和 useradd -r -g mysql mysql
[root@zyq mysql]# groupadd mysql
[root@zyq mysql]# useradd -r -g mysql mysql
#useradd -r参数表示mysql用户是系统用户,不可用于登录系统
将/usr/local/mysql/mysql-5.7
的所有者及所属组改为mysql
[root@zyq mysql]# chown -R mysql.mysql /usr/local/mysql/mysql-5.7
[root@zyq mysql]# chown -R mysql.mysql /usr/local/mysql/data
[root@zyq mysql]# chown -R mysql /usr/local/mysql/data
[root@zyq mysql]# chown -R mysql /usr/local/mysql/mysql-5.7
[root@zyq mysql]# chmod -R 755 /usr/local/mysql/mysql-5.7
在/usr/local/mysql/mysql-5.7/support-files
目录下创建my_default.cnf
[root@zyq support-files]# vim my_default.cnf
修修或者添加一下内容
[client]
no-beep
socket = /tmp/mysql.sock
# pipe
# socket=0.0
port=3306
[mysql]
default-character-set=utf8
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir = /usr/local/mysql/mysql-5.7
datadir = /usr/local/mysql/data
port=3306
log-error = /usr/local/mysql/data/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid
#skip-grant-tables
skip-name-resolve
socket = /tmp/mysql.sock
character-set-server=utf8
default-storage-engine=INNODB
explicit_defaults_for_timestamp = true
# Server Id.
server-id=1
max_connections=2000
query_cache_size=0
table_open_cache=2000
tmp_table_size=246M
thread_cache_size=300
#限定用于每个数据库线程的栈大小。默认设置足以满足大多数应用
thread_stack = 192k
key_buffer_size=512M
read_buffer_size=4M
read_rnd_buffer_size=32M
innodb_data_home_dir = /usr/local/mysql/data
innodb_flush_log_at_trx_commit=0
innodb_log_buffer_size=16M
innodb_buffer_pool_size=256M
innodb_log_file_size=128M
innodb_thread_concurrency=128
innodb_autoextend_increment=1000
innodb_buffer_pool_instances=8
innodb_concurrency_tickets=5000
innodb_old_blocks_time=1000
innodb_open_files=300
innodb_stats_on_metadata=0
innodb_file_per_table=1
innodb_checksum_algorithm=0
back_log=80
flush_time=0
join_buffer_size=128M
max_allowed_packet=1024M
max_connect_errors=2000
open_files_limit=4161
query_cache_type=0
sort_buffer_size=32M
table_definition_cache=1400
binlog_row_event_max_size=8K
sync_master_info=10000
sync_relay_log=10000
sync_relay_log_info=10000
#批量插入数据缓存大小,可以有效提高插入效率,默认为8M
bulk_insert_buffer_size = 64M
interactive_timeout = 120
wait_timeout = 120
log-bin-trust-function-creators=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
拷贝my_default.cnf
文件到/etc/my.cnf
如果提示是否覆盖,y
[root@zyq support-files]# cp my_default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[root@zyq support-files]#
修改mysql.server文件,进入/usr/local/mysql/mysql-5.7/support-files
目录修改mysql.server
,修改内容如下找到mysqld_pid_file_path=
修改MySQL的安装路径及数据路径
# The following variables are only set for letting mysql.server find things.
# Set some defaults
mysqld_pid_file_path=
if test -z "$basedir"
then
basedir=/usr/local/mysql/mysql-5.7
bindir=/usr/local/mysql/mysql-5.7/bin
if test -z "$datadir"
then
datadir=/usr/local/mysql/data
fi
sbindir=/usr/local/mysql/mysql-5.7/bin
libexecdir=/usr/local/mysql/mysql-5.7/bin
else
bindir="$basedir/bin"
if test -z "$datadir"
then
datadir="$basedir/data"
fi
sbindir="$basedir/sbin"
libexecdir="$basedir/libexec"
fi
把启动脚本放到开机初始化目录进入/usr/local/mysql/mysql-5.7/support-files
目录下执行cp mysql.server /etc/init.d/mysql
[root@zyq support-files]# cp mysql.server /etc/init.d/mysql
[root@zyq support-files]#
初始化 mysqld 进入到/usr/local/mysql/mysql-5.7
执行./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7/ --datadir=/usr/local/mysql/data/
[root@zyq mysql-5.7]#./bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7/ --datadir=/usr/local/mysql/data/
初始化完成之后进入/usr/local/mysql/data
,查看cat mysqld.log
日志找出随机生成mysql数据库登录的临时密码
[root@zyq data]# cat mysqld.log
2020-02-21T14:02:25.896593Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-02-21T14:02:25.896962Z 0 [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-02-21T14:02:25.896973Z 0 [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
2020-02-21T14:02:26.710078Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-02-21T14:02:26.791482Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-02-21T14:02:26.902798Z 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: caa64450-54b2-11ea-8c3c-000c2923d700.
2020-02-21T14:02:26.904801Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-02-21T14:02:28.091585Z 0 [Warning] CA certificate ca.pem is self signed.
2020-02-21T14:02:28.293469Z 1 [Note] A temporary password is generated for root@localhost: s7kh.#l8%O6p
[root@zyq data]#
找出临时密码:2020-02-21T14:02:28.293469Z 1 [Note] A temporary password is generated for root@localhost: s7kh.#l8%O6p
密码就是:s7kh.#l8%O6p
记住密码随后登陆需要
启动mysql服务service mysql start
[root@zyq support-files]# service mysql start
Starting MySQL.. SUCCESS!
进入/usr/local/mysql/mysql-5.7/bin
执行./mysql -u root -p
登录mysql,密码为初始密码
[root@zyq bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.29
Copyright (c) 2000, 2020, 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=password('密码');
mysql> set password=password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
授权root权限使得外部地址使用root登陆grant all privileges on *.* to root@'%' identified by '123456';
mysql> grant all privileges on *.* to root@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0.00 sec)
刷新权限:flush privileges;
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
至此mysql源码安装已完成
本人亲自安装测式,写此博文作为记录;
docker安装mysql传送门:https://blog.csdn.net/iT_MaNongking/article/details/104405756