千家信息网

MySQL5.6二进制包方式安装流程讲义

发表于:2025-01-22 作者:千家信息网编辑
千家信息网最后更新 2025年01月22日,本文主要给大家介绍MySQL5.6二进制包方式安装流程讲义,希望可以给大家补充和更新些知识,如有其它问题需要了解的可以持续在行业资讯里面关注我的更新文章的。MySQL基于二进制格式安装的优点在于,它是
千家信息网最后更新 2025年01月22日MySQL5.6二进制包方式安装流程讲义

本文主要给大家介绍MySQL5.6二进制包方式安装流程讲义,希望可以给大家补充和更新些知识,如有其它问题需要了解的可以持续在行业资讯里面关注我的更新文章的。

MySQL基于二进制格式安装的优点在于,它是针对特定平台专门优化过的,安装的时候也不需要考虑环境的要求,直接解压就可以,本文基于MySQL5.6.38版本,下载地址为:
https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz
1,下载MySQL二进制包:

    [root@localhost ~]# mkdir /root/soft/ -pv    [root@localhost ~]# cd soft/    [root@localhost soft]# wget https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz

2,解压到/usr/local下:

[root@localhost soft]# tar xf mysql-5.6.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

3,创建软链接:

[root@localhost soft]# cd /usr/local/[root@localhost local]# ln -sv mysql-5.6.38-linux-glibc2.12-x86_64/ mysql

4,创建mysql数据目录:

[root@localhost ~]# mkdir /data/mydata -pv 

4,创建mysql用户,mysql组,授权数据目录:

[root@localhost ~]# groupadd -r mysql[root@localhost ~]# useradd -r -g mysql -s /sbin/nologin -M -d /data/mydata mysql[root@localhost ~]# chown -R mysql:mysql /data/mydata/

5,初始化数据库:

[root@localhost ~]# cd /usr/local/mysql[root@localhost mysql]# chown -R mysql.mysql .[root@localhost mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mydata/ --user=mysqlFATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:Data::Dumper

这里出现一个报错提示我有Perl模块没有装,于是我照常安装了perl-devel,perl等软件包,再初始化数据发现还是报错,搜索了下原来是perl-Data-Dumper.x86_64 0:2.145-3.el7这个包,报错的信息提示的很明显,好吧,下次一定好好看报错信息。解决方法也很简单,直接yum install即可。

[root@localhost mysql]# yum list  perl-Data-DumperLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfile * base: mirrors.cn99.com * extras: mirrors.cn99.com * updates: centos.ustc.edu.cnAvailable Packagesperl-Data-Dumper.x86_64           [root@localhost mysql]# yum install perl-Data-Dumper -y

再次执行:

[root@localhost mysql]# ./scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mydata/ --user=mysqlInstalling MySQL system tables.../usr/local/mysql/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

又一个报错出现,这个提示表明libaio这个模块不存在,好,缺啥咱就装啥。

[root@localhost mysql]# yum install libaio -y

然后再执行mysql_install_db脚本初始化数据库,这次没有报错,当看到OK字样时,表示数据库初始化完成。

6,设置mysql数据库配置文件。这里要注意mysql5.6解压目录下的 support-files目录中只有my-default.cnf这样一个默认配置文件,而且里面基本没有配置,多为注释,这和mysql5.5的区别比较大,5.5的该目录下会有 my-huge.cnf my-innodb-heavy-4G.cnf my-large.cnf my-medium.cnf my-small.cnf 这样的配置文件,可以根据自身云服务器的情况自行选择。既然如此,就只能自己配置my.cnf了。

[root@localhost ~]# vi /etc/my.cnf[client]#password       = your_passwordport            = 3306socket          = /tmp/mysql.sock[mysqld]port            = 3306socket          = /tmp/mysql.sock#datadir = /usr/local/mysql/vardatadir = /data/mydata/basedir = /usr/local/mysql/pid-file = /data/mydata/mysql.pidskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mthread_cache_size = 8query_cache_size = 8Mtmp_table_size = 16M#skip-networkingmax_connections = 500max_connect_errors = 100open_files_limit = 65535log-bin=mysql-binbinlog_format=mixedserver-id       = 1expire_logs_days = 10default_storage_engine = InnoDBinnodb_file_per_table = 1innodb_data_home_dir = /data/mydata/innodb_data_file_path = ibdata1:10M:autoextendinnodb_log_group_home_dir = /data/mydata/innodb_buffer_pool_size = 16Minnodb_additional_mem_pool_size = 2Minnodb_log_file_size = 5Minnodb_log_buffer_size = 8Minnodb_flush_log_at_trx_commit = 1innodb_lock_wait_timeout = 50[mysqldump]quickmax_allowed_packet = 16M[mysql]no-auto-rehash[myisamchk]key_buffer_size = 20Msort_buffer_size = 20Mread_buffer = 2Mwrite_buffer = 2M[mysqlhotcopy]interactive-timeout

7,导出PATH环境变量:

[root@localhost ~]# echo "export PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh[root@localhost ~]# . /etc/profile.d/mysql.sh

8,导出mysql头文件到系统头文件目录:

[root@localhost ~]# ln -sv /usr/local/mysql/include  /usr/include/mysql

9,输出mysql库文件到系统库文件的路径:

[root@localhost ~]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf[root@localhost ~]# ldconfig -v

10,启动mysqld服务:

[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld[root@localhost mysql]# chkconfig mysqld on [root@localhost mysql]# /etc/init.d/mysqld start

这里要注意一下,/etc/init.d/mysqld这个脚本中有如下几个地方要修改:

basedir=/usr/local/mysqldatadir=/data/mydata/mysqld_pid_file_path=/data/mydata/mysql.pid

这时候mysql就已经启动了:

[root@localhost mysql]# mysqlWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.6.38-log 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 itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> mysql> use mysql Database changedmysql> delete from mysql.user where (user,host) not in (select 'root', 'localhost'); #删除多余的用户mysql> update user set password=password('QWER@@111') where user='root'; #修改root密码Query OK, 1 row affected (0.00 sec)Rows matched: 1  Changed: 1  Warnings: 0mysql> select user,host,password from user;+------+-----------+-------------------------------------------+| user | host      | password                                  |+------+-----------+-------------------------------------------+| root | localhost | *16FF293CF039130E27DC275D8B47EBB0754FFE9F |+------+-----------+-------------------------------------------+1 row in set (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)

至此,MySQL数据库安装完成。

看了以上关于MySQL5.6二进制包方式安装流程讲义,希望能给大家在实际运用中带来一定的帮助。本文由于篇幅有限,难免会有不足和需要补充的地方,如有需要更加专业的解答,可在官网联系我们的24小时售前售后,随时帮您解答问题的。

0