使用vmware搭建的虚拟机,服务器的系统是linux centos7,mysql版本是5.7.26,下载链接:
下载方式一:
官网地址(速度较慢):https://dev.mysql.com/downloads/mysql/
可以直接下载到本地电脑,然后再上传到虚拟机去。
或者,直接在centos7上使用命令下载:wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
下载方式二:
使用清华镜像下载(速度较快,推荐):
wget https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.7/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
卸载旧版MySQL
安装相关依赖
yum -y install make gcc-c++ cmake bison-devel ncurses-devel numactl libaio
本地安装路径说明
在原始安装目录添加:data、logs、tmp目录,并新建my.cnf文件
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# pwd
/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64
##初始的mysql的所有文件如下:
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# ls
bin COPYING docs include lib man README share support-files
##新建data目录,存放数据;logs目录日志;tmp 临时目录
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# mkdir data logs tmp
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# ls
bin COPYING data docs include lib logs man README share support-files tmp
#官网说:从5.7.18开始不在二进制包中提供my-default.cnf文件。参考:https://dev.mysql.com/doc/refman/5.7/en/binary-installation.html
#如下,在5.7.26原生的安装包里,support-files目录下是没有my.cnf文件的
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# cd support-files/
[root@132 support-files]# ls
magic mysqld_multi.server mysql-log-rotate mysql.server
#自己建立一个my.cnf文件
[root@132 support-files]# touch my.cnf
[root@132 support-files]# ls
magic my.cnf mysqld_multi.server mysql-log-rotate mysql.server
my.cnf中的配置如下(相关目录要适配自己的情况):
#简单模板如下:
[client]
port = 3306
socket = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/tmp/mysql.sock
[mysqld]
user = root
basedir = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/
datadir = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/data
port = 3306
user=root
socket = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/tmp/mysql.sock
pid-file = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/tmp/mysqld.pid
tmpdir = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/tmp
skip_name_resolve = 1
symbolic-links=0
max_connections = 2000
group_concat_max_len = 1024000
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
lower_case_table_names = 1
log_timestamps=SYSTEM
character-set-server = utf8
interactive_timeout = 1800
wait_timeout = 1800
max_allowed_packet = 32M
binlog_cache_size = 4M
sort_buffer_size = 2M
read_buffer_size = 4M
join_buffer_size = 4M
tmp_table_size = 96M
max_heap_table_size = 96M
max_length_for_sort_data = 8096
#logs
server-id = 1
log-error = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/logs/error.log
slow_query_log = 1
slow_query_log_file = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/logs/slow.log
long_query_time = 3
log-bin = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/logs/binlog
binlog_format = row
expire_logs_days = 5
log_bin_trust_function_creators = 1
#relay-log = /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/logs/relay-bin
#relay-log-recovery = 1
#relay_log_purge = 1
#innodb
innodb_file_per_table = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 256M
innodb_log_files_in_group = 2
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_flush_neighbors = 0
innodb_flush_method = O_DIRECT
innodb_autoinc_lock_mode = 2
innodb_read_io_threads = 8
innodb_write_io_threads = 8
innodb_buffer_pool_size = 2G
将/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/support-files目录下的my.cnf拷贝到/etc/mycnf
[root@132 support-files]# cp my.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? yes
[root@132 support-files]#
修改mysql.server
[root@132 support-files]# ls
magic my.cnf mysqld_multi.server mysql-log-rotate mysql.server
[root@132 support-files]# cp mysql.server /etc/init.d/mysql
[root@132 support-files]# vim /etc/init.d/mysql
修改mysql.server中的目录位置
#mysql安装的根目录
basedir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64
#mysql的数据目录
datadir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/data
添加环境变量
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# echo "PATH=$PATH:/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/bin" >> /etc/profile
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# source /etc/profile
-bash: /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/bin: Is a directory
初始化mysql
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# bin/mysqld --initialize --user=root --basedir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64 --datadir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/data
2019-11-29T06:14:20.050388Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-29T06:14:20.197918Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-11-29T06:14:20.227777Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-11-29T06:14:20.284894Z 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: 7b057ac5-126f-11ea-82b6-0050562a43a4.
2019-11-29T06:14:20.286475Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-11-29T06:14:20.289503Z 1 [Note] A temporary password is generated for root@localhost: tqV!gGa5=IXe
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]#
[root@132 mysql-5.7.26-linux-glibc2.12-x86_64]# bin/mysql_ssl_rsa_setup --datadir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/data
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生成的初始密码:tqV!gGa5=IXe
启动mysql服务:
[root@132 support-files]# service mysql start
Starting MySQL.Logging to '/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/logs/error.log'.
.. SUCCESS!
[root@132 support-files]# service mysql status
SUCCESS! MySQL running (11279)
修改mysql的密码(初始密码:tqV!gGa5=IXe):
[root@132 support-files]# 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.26-log
Copyright (c) 2000, 2019, 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.
##修改密码为‘root’
mysql> set password=password('root');
Query OK, 0 rows affected, 1 warning (0.01 sec)
##授权
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
##测试一下是否正常
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select host,user from user;
+-----------+---------------+
| host | user |
+-----------+---------------+
| % | root |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
+-----------+---------------+
4 rows in set (0.00 sec)
##退出mysql
mysql> exit;
Bye
[root@132 support-files]#
至此,centos7上的服务端的mysql服务已正常启动,下面,用本地的navicat测试一波:
至此,linux centos7环境下安装mysql大功告成!!!
补充:
–退出mysql命令窗口
#exit
–查看mysql状态
#service mysql status
–停止mysql
#service mysql stop
–启动mysql
#service mysql start
[root@132 support-files]# service mysql stop
Shutting down MySQL.... SUCCESS!
[root@132 support-files]# ps -ef|grep mysql
root 12631 7403 0 14:54 pts/3 00:00:00 grep --color=auto mysql
[root@132 support-files]# service mysql status
ERROR! MySQL is not running
[root@132 support-files]# service mysql start
Starting MySQL.. SUCCESS!
[root@132 support-files]# service mysql status
SUCCESS! MySQL running (13351)
[root@132 support-files]# ps -ef|grep mysql
root 12692 1 0 14:54 pts/3 00:00:00 /bin/sh /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64//bin/mysqld_safe --datadir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/data --pid-file=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/tmp/mysqld.pid
root 13351 12692 4 14:54 pts/3 00:00:00 /usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/bin/mysqld --basedir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/ --datadir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/data --plugin-dir=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64//lib/plugin --user=root --log-error=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/logs/error.log --pid-file=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/tmp/mysqld.pid --socket=/usr/hugo/soft/mysql/mysql-5.7.26-linux-glibc2.12-x86_64/tmp/mysql.sock --port=3306
root 13426 7403 0 14:54 pts/3 00:00:00 grep --color=auto mysql
[root@132 support-files]#