mysql - 使用glibc二进制包方式安装mysql-5.6.50

本文详细介绍了在Linux环境下安装MySQL5.6的步骤,包括系统环境检查、旧版本卸载、依赖库安装、创建安装目录、用户组与用户管理、数据库文件拷贝及初始化。安装过程中涉及的命令行操作、日志输出和安全设置等关键环节均有详尽说明。安装完成后,还提醒了设置密码和安全初始化数据库的重要性。
摘要由CSDN通过智能技术生成

【前置准备】

1.系统环境信息查看确认

# yum install -y redhat-lsb
# lsb_release -a              -- 查看系统版本
# uname -a                    -- 查看内核版本
# cat /etc/issue

2.卸载旧版本

# find / -name mysql
# ps 检查:ps -ef|grep mysql|grep -v grep
# rpm -qa | grep mysql  -- 检查系统是否已经安装过mysql 和 mariadb,如果有,卸载掉
# rpm -qa | grep mariadb
# rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
# 再次检查:rpm -qa|grep -i mysql   -- 若返回空,则清空下载完毕
# 删除残余目录:rm -rf mysql/
# 确保没有旧版本的:/etc/my.conf文件,有则删除掉
# find / -name my.cnf
# rm -rf /etc/my.cnf

3.依赖库与工具安装

# yum install -y redhat-lsb
# yum -y install lrzsz
# sudo yum -y install libaio libaio-devel  
# sudo yum -y install gcc gcc-c++ glibc-headers cmake gcc-c++* make ncurses-devel vim net-tools perl autoconf

4.创建安装目录:

官方默认的安装目录:/usr/local/mysql
官方默认的数据目录:/usr/local/mysql/data

# mkdir -p /usr/local/mysql

5.创建用户组和用户:

# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
或者:
# useradd mysql -r -s /sbin/nologin   - 不允许使用mysql登录服务器,只能用于管理mysql服务
# id mysql
uid=997(mysql) gid=995(mysql) 组=995(mysql)

# mkdir -p /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql

【正式安装】

1.下载:

https://dev.mysql.com/downloads/mysql/
https://downloads.mysql.com/archives/community/
https://downloads.mysql.com/archives/get/p/23/file/mysql-5.5.62-linux-glibc2.12-x86_64.tar.gz
https://mirrors.huaweicloud.com/mysql/Downloads/MySQL-5.6/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz

2.解压:tar -zxvf  mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz

3.进入解压目录,拷贝数据库文件到安装目录

# cd mysql-5.6.50-linux-glibc2.12-x86_64
# cp -a ./* /usr/local/mysql/

4.手动初始化mysql

# ll -d /usr/local/mysql/

# 更改mysql安装目录权限
# chown -R mysql:mysql /usr/local/mysql

# cd /usr/local/mysql/scripts
# 二进制包安装必须指定basedir 与 datadir
# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

显示如下日志:
---------------------------------------------------------------------------------------------------------------------------------------
Installing MySQL system tables...2020-12-28 23:02:25 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-12-28 23:02:25 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-12-28 23:02:25 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.50) starting as process 9499 ...
2020-12-28 23:02:25 9499 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-12-28 23:02:25 9499 [Note] InnoDB: The InnoDB memory heap is disabled
2020-12-28 23:02:25 9499 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-12-28 23:02:25 9499 [Note] InnoDB: Memory barrier is not used
2020-12-28 23:02:25 9499 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-12-28 23:02:25 9499 [Note] InnoDB: Using Linux native AIO
2020-12-28 23:02:25 9499 [Note] InnoDB: Using CPU crc32 instructions
2020-12-28 23:02:25 9499 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-12-28 23:02:25 9499 [Note] InnoDB: Completed initialization of buffer pool
2020-12-28 23:02:25 9499 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2020-12-28 23:02:25 9499 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2020-12-28 23:02:25 9499 [Note] InnoDB: Database physically writes the file full: wait...
2020-12-28 23:02:25 9499 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2020-12-28 23:02:26 9499 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2020-12-28 23:02:26 9499 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2020-12-28 23:02:26 9499 [Warning] InnoDB: New log files created, LSN=45781
2020-12-28 23:02:26 9499 [Note] InnoDB: Doublewrite buffer not found: creating new
2020-12-28 23:02:26 9499 [Note] InnoDB: Doublewrite buffer created
2020-12-28 23:02:26 9499 [Note] InnoDB: 128 rollback segment(s) are active.
2020-12-28 23:02:26 9499 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-12-28 23:02:26 9499 [Note] InnoDB: Foreign key constraint system tables created
2020-12-28 23:02:26 9499 [Note] InnoDB: Creating tablespace and datafile system tables.
2020-12-28 23:02:26 9499 [Note] InnoDB: Tablespace and datafile system tables created.
2020-12-28 23:02:26 9499 [Note] InnoDB: Waiting for purge to start
2020-12-28 23:02:26 9499 [Note] InnoDB: 5.6.50 started; log sequence number 0
2020-12-28 23:02:26 9499 [Note] RSA private key file not found: /usr/local/mysql/scripts/data//private_key.pem. Some authentication plugins will not work.
2020-12-28 23:02:26 9499 [Note] RSA public key file not found: /usr/local/mysql/scripts/data//public_key.pem. Some authentication plugins will not work.
2020-12-28 23:02:27 9499 [Note] Binlog end
2020-12-28 23:02:27 9499 [Note] InnoDB: FTS optimize thread exiting.
2020-12-28 23:02:27 9499 [Note] InnoDB: Starting shutdown...
2020-12-28 23:02:28 9499 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2020-12-28 23:02:28 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-12-28 23:02:28 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
2020-12-28 23:02:28 0 [Note] /usr/local/mysql//bin/mysqld (mysqld 5.6.50) starting as process 9524 ...
2020-12-28 23:02:28 9524 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-12-28 23:02:28 9524 [Note] InnoDB: The InnoDB memory heap is disabled
2020-12-28 23:02:28 9524 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2020-12-28 23:02:28 9524 [Note] InnoDB: Memory barrier is not used
2020-12-28 23:02:28 9524 [Note] InnoDB: Compressed tables use zlib 1.2.11
2020-12-28 23:02:28 9524 [Note] InnoDB: Using Linux native AIO
2020-12-28 23:02:28 9524 [Note] InnoDB: Using CPU crc32 instructions
2020-12-28 23:02:28 9524 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2020-12-28 23:02:28 9524 [Note] InnoDB: Completed initialization of buffer pool
2020-12-28 23:02:28 9524 [Note] InnoDB: Highest supported file format is Barracuda.
2020-12-28 23:02:28 9524 [Note] InnoDB: 128 rollback segment(s) are active.
2020-12-28 23:02:28 9524 [Note] InnoDB: Waiting for purge to start
2020-12-28 23:02:28 9524 [Note] InnoDB: 5.6.50 started; log sequence number 1625977
2020-12-28 23:02:28 9524 [Note] RSA private key file not found: /usr/local/mysql/scripts/data//private_key.pem. Some authentication plugins will not work.
2020-12-28 23:02:28 9524 [Note] RSA public key file not found: /usr/local/mysql/scripts/data//public_key.pem. Some authentication plugins will not work.
2020-12-28 23:02:28 9524 [Note] Binlog end
2020-12-28 23:02:28 9524 [Note] InnoDB: FTS optimize thread exiting.
2020-12-28 23:02:28 9524 [Note] InnoDB: Starting shutdown...
2020-12-28 23:02:30 9524 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

  /usr/local/mysql//bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql//bin/mysqladmin -u root -h servernode1 password 'new-password'

Alternatively you can run:

  /usr/local/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.      ---- 重点关注!!!

See the manual for more instructions.

You can start the MySQL daemon with:

  cd . ; /usr/local/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

  cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

  http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as /usr/local/mysql//my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

---------------------------------------------------------------------------------------------------------------------------------------

# 拷贝启动脚本到目录:/etc/init.d/
# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

# 启动:
# service mysql start
# service mysql status

# 验证
# ss -naltp|grep mysqld
# ps -ef|grep mysql

【后续配置】

1.根据安装日志提示设置密码:

  /usr/local/mysql//bin/mysqladmin -u root password 'new-password'
  /usr/local/mysql//bin/mysqladmin -u root -h servernode1 password 'new-password'


# /usr/local/mysql//bin/mysqladmin -u root password 'root123'
# hostname
# /usr/local/mysql//bin/mysqladmin -u root -h ${hostname} password 'root123'

2.安全初始化数据库

# cd /usr/local/mysql/
# ./bin/mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] n    -- 是否改变当前root用户的密码?
 ... skipping.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y   -- 是否删除匿名用户账号?
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n    -- 是否禁用root用户远程登录功能?
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y  -- 删除测试库以及对应的权限?
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y   -- 重新加载权限表数据?
 ... Success!

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...


# 测试登录
# mysql -u root -p
-bash: mysql: 未找到命令

# 设置环境变量
# vim /etc/profile
# config mysql path
export PATH=$PATH:/usr/local/mysql/bin

# source /etc/profile

# 再次测试登录
# mysql -u root -p
Enter password:
mysql> show databases;
mysql> create database db_cat;
# 保证主节点可以通过指定用户(比如root用户)远程访问!!!
mysql> use mysql;
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root123' with grant option;
mysql> flush privileges;
mysql> exit

安装完成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值