技术笔记分享

1)下载或者上传二进制包

[root@db01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
#或者
[root@db01 ~]# rz mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz

2)安装依赖

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

3)解压

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

4)创建自定义目录

[root@db03 ~]# mkdir /service

5)移动并改名

[root@db03 ~]# mv mysql-5.6.42-linux-glibc2.12-x86_64 /service/mysql-5.6.42

6)做软连接

[root@db03 ~]# ln -s /service/mysql-5.6.42 /service/mysql

7)创建用户

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

8)拷贝启动文件和配置文件

[root@db03 ~]# cd /service/mysql/support-files/
[root@db03 /service/mysql/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y
[root@db03 /service/mysql/support-files]# cp mysql.server /etc/init.d/mysqld

9)初始化

[root@db03 ~]# cd /service/mysql/scripts/
[root@db03 /service/mysql/scripts]# ./mysql_install_db --user=mysql --basedir=/service/mysql --datadir=/service/mysql/data

10)配置system管理启动MySQL

[root@db03 ~]# vim /usr/lib/systemd/system/mysqld.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=/service/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

#重载
[root@db03 ~]# systemctl daemon-reload

11)启动数据库

#1.使用system启动
[root@db03 ~]# systemctl start mysqld
#查看进程启动失败,没有任何报错

#2.使用mysqld启动脚本启动
[root@db03 ~]# /etc/init.d/mysqld start
/etc/init.d/mysqld: line 244: my_print_defaults: command not found
/etc/init.d/mysqld: line 264: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
#原因:二进制的包是源码包已经生成编译安装完成的,在cmake阶段已经指定了所有的目录都是/usr/local/mysql,所以启动时所有程序都去找/usr/local/mysql目录,没有该目录,所以启动失败

#3.解决启动问题
1)方法一:做软连接
[root@db03 ~]# ln -s /service/mysql /usr/local/mysql

2)方法二:修改启动文件
[root@db03 ~]# vim /etc/init.d/mysqld
basedir=/service/mysql
datadir=/service/mysql/data

#4.再次测试启动
[root@db03 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
#或者
[root@db03 ~]# systemctl start mysqld

12)设置环境变量

[root@db02 ~]# vim /etc/profile.d/mysql.sh
export PATH=/service/mysql/bin:$PATH

[root@db02 ~]# source /etc/profile

发表评论

邮箱地址不会被公开。 必填项已用*标注