• 欢迎访问显哥博客,本网站纯属学习技术,绝无商业用途,欢迎小伙伴们共同学习!研究技术!QQ:52249909 加我QQ
  • 世界75亿人,这么小的概率,能认识你,是我一生的幸运,不妨加个QQ接触一下:52249909 加我QQ

企业级安装部署MySQL数据库(二进制安装)【显哥出品,必为精品】

MySQL lixian 4年前 (2020-06-05) 19654次浏览 0个评论 扫描二维码

1.上传或者下载包(两种方式选择一种即可)

[root@db01 ~]# rz mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz(如果采用这种上传方式,需要自行下载mysql5.6的源码包,建议用下面wget下载方式)
[root@db01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

2.安装依赖包

[root@db01 ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ cmake autoconf openssl openssl-devel

3.解压安装包

[root@db01 ~]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz

4.移动目录并改名

[root@db01 ~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.46

5.做软连接

[root@db01 ~]# ln -s /usr/local/mysql-5.6.46 /usr/local/mysql

6.创建数据库用户

[root@db01 ~]# useradd mysql -s /sbin/nologin -M

7.拷贝配置文件和启动文件

[root@db01 ~]# cd /usr/local/mysql/support-files/

#拷贝mysql默认配置文件
[root@db01 support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y  

#拷贝mysql启动脚本
[root@db01 support-files]# cp mysql.server /etc/init.d/mysqld

8.初始化数据库

#1.进入初始化的目录
[root@db01 ~]# cd /usr/local/mysql/scripts/
[root@db01 scripts]# ll
total 36
-rwxr-xr-x 1 7161 31415 34977 Sep 27  2019 mysql_install_db

#2.执行初始化命令
[root@db01 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/

#3.判断是否执行成功
	1.执行过程中出现两个ok
	2.数据目录下有新文件 ll /usr/local/mysql/data/
	#数据安装好默认有四个库:
		mysql
		test
		performance_schema
		information_schema
	初始化之前只有一个test库,初始化的作用就是生成其他三个库

9.启动数据库并验证服务启动

[root@db01 ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/db01.err'.
 SUCCESS!

 [root@db01 ~]# ps -ef | grep [m]ysql
mysql     23893      1  1 20:28 ?        00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf

[root@db01 ~]# netstat -lntp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      23893/mysqld

#停止数据库
[root@db01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS

10.配置system管理mysql

#1.配置system管理
[root@db01 ~]# vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

#2.重新读取启动文件列表
[root@db01 ~]# systemctl daemon-reload

#3.使用system启动MySQL
[root@db01 ~]# systemctl start mysql
#停止数据库命令
[root@db01 ~]# systemctl stop mysql

11.登录MySQL

#方式一:
[root@db01 ~]# /usr/local/mysql/bin/mysql

#方式二:配置环境变量后登录(推荐)
[root@db01 ~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
[root@db01 ~]# source /etc/profile
[root@db01 ~]# mysql
#设置root登录密码(输入两次密码,输入的时候密码是看不到的 输入请谨慎 防止输错)
[root@db01 ~]#mysqladmin -uroot password 

本站博主 , 版权所有丨如未注明 , 均为原创
转载请注明原文链接:企业级安装部署MySQL数据库(二进制安装)【显哥出品,必为精品】
喜欢 (2)

您必须 登录 才能发表评论!