Centos6+mysql-5.7.29
一 安装前准备
本文档限于Centos6+mysql-5.7.29及以下,实操安装,另附mysql-5.7.29 linux安装包百度云地址:https://pan.baidu.com/s/1XjYCFWkIMa-SJy70JAV0rg
提取码:f3hn
1、检查是否已经安装过mysql,执行命令:rpm -qa | grep mysql
[hadoop@gyh101 ~]$ rpm -qa | grep mysql
mysql-connector-odbc-5.1.5r1144-7.el6.x86_64
mysql-5.1.73-8.el6_8.x86_64
mysql-libs-5.1.73-8.el6_8.x86_64
mysql-server-5.1.73-8.el6_8.x86_64
从执行结果,可以看出我们已经安装了mysql-5.1.73-8.el6_8.x86_64,执行删除命令将列表中mysql全部产出
[hadoop@gyh101 ~]$ sudo rpm -e --nodeps mysql-connector-odbc-5.1.5r1144-7.el6.x86_64
[sudo] password for hadoop:
[hadoop@gyh101 ~]$ sudo rpm -e --nodeps mysql-5.1.73-8.el6_8.x86_64
[hadoop@gyh101 ~]$ sudo rpm -e --nodeps mysql-libs-5.1.73-8.el6_8.x86_64
[hadoop@gyh101 ~]$ sudo rpm -e --nodeps mysql-server-5.1.73-8.el6_8.x86_64
再次执行查询命令,查看是否删除
[hadoop@gyh101 ~]$ rpm -qa | grep mysql
[hadoop@gyh101 ~]$
2、查询所有Mysql对应的文件夹
[hadoop@gyh101 ~]$ whereis mysql
mysql: /usr/lib64/mysql /usr/share/mysql
[hadoop@gyh101 ~]$ sudo find / -name mysql
/usr/lib64/perl5/auto/DBD/mysql
/usr/lib64/perl5/DBD/mysql
/usr/lib64/mysql
/usr/share/mysql
删除相关目录或文件
[hadoop@gyh101 ~]$ sudo rm -rf /usr/lib64/mysql /usr/share/mysql /usr/lib64/perl5/auto/DBD/mysql /usr/lib64/perl5/DBD/mysql /usr/lib64/mysql /usr/share/mysql
[sudo] password for hadoop:
验证是否删除完毕
[hadoop@gyh101 ~]$ whereis mysql
mysql:
[hadoop@gyh101 ~]$ sudo find / -name mysql
[hadoop@gyh101 ~]$
检查mysql用户组和用户是否存在,如果没有,则创建;这里我使用hadoop用户,读者自行创建mysql用户即可。
[root@localhost /]# cat /etc/group | grep mysql
[root@localhost /]# cat /etc/passwd |grep mysql
[root@localhost /]# groupadd mysql
[root@localhost /]# useradd -r -g mysql mysql
[root@localhost /]#
二 安装Mysql
1.在/opt/路径下创建software、module路径,之后将下载好的mysql安装包拷贝到sofeware路径,将安装包解压到module路径:
解压到module路径:
[hadoop@gyh101 software]$ tar -zxvf mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz -C /opt/module/
查看module:
[hadoop@gyh101 software]$ cd /opt/module/
[hadoop@gyh101 module]$ ll
总用量 16
drwxr-xr-x. 15 hadoop hadoop 4096 4月 15 09:29 hadoop-2.7.2
drwxr-xr-x. 8 hadoop hadoop 4096 7月 22 2017 jdk1.8.0_144
drwxrwxr-x. 9 hadoop hadoop 4096 5月 20 12:11 mysql-5.7.29-linux-glibc2.12-x86_64
drwxr-xr-x. 15 hadoop hadoop 4096 4月 20 20:06 zookeeper-3.4.14
将mysql-5.7.29-linux-glibc2.12-x86_64重命名为mysql-5.7.29
[hadoop@gyh101 module]$ mv mysql-5.7.29-linux-glibc2.12-x86_64 mysql-5.7.29
2.在/opt/module/mysql-5.7.29目录下创建data目录
[hadoop@gyh101 mysql-5.7.29]$ mkdir data
3.更改mysql-5.7.29目录下所有的目录及文件夹所属的用户组和用户,以及权限;这里我由于直接使用hadoop用户操作,无需更改;如果您使用root用户拷贝解压文件的话,需要将文件归属改为您自定义的操作用户mysql:
[root@localhost /]# chown -R mysql:mysql /usr/local/mysql
[root@localhost /]# chmod -R 755 /usr/local/mysql
4.编译安装并初始化mysql,务必记住初始化输出日志末尾的密码(标红位置分别为您自定义用户名、数据库管理员临时密码;)
[hadoop@gyh101 bin]$ ./mysqld --initialize --user=hadoop --datadir=/opt/module/mysql-5.7.29/data --basedir=/opt/module/mysql-5.7.29/
2020-05-20T04:19:52.085835Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2020-05-20T04:19:52.085902Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)
2020-05-20T04:19:52.086029Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2020-05-20T04:19:52.285540Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-05-20T04:19:52.345490Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-05-20T04:19:52.466941Z 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: 26f262ea-9a51-11ea-bf46-000c298f807c.
2020-05-20T04:19:52.470578Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-20T04:19:53.177239Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-20T04:19:53.302965Z 1 [Note] A temporary password is generated for root@localhost: uw4(LiklUdin
记录日志最末尾位置root@localhost:后的字符串,此字符串为mysql管理员临时登录密码
补充说明:
第4步时,可能会出现错误:
出现该问题首先检查该链接库文件有没有安装使用 命令进行核查
[root@localhost bin]# rpm -qa|grep libaio [root@localhost bin]#
运行命令后发现系统中无该链接库文件
[root@localhost bin]# yum install libaio-devel.x86_64
安装成功后,继续运行数据库的初始化命令,此时可能会出现如下错误:
执行如下命令后:
[root@localhost bin]# yum -y install numactl
执行无误之后,再重新执行第4步初始化命令,无误之后再进行第5步操作!
6.修改mysql启动脚本,指定mysql安装路径和data路径
[hadoop@gyh101 mysql-5.7.29]$ vim /opt/module/mysql-5.7.29/support-files/mysql.server
修改mysql.server中的basedir和datadir
7.启动mysql
[hadoop@gyh101 mysql-5.7.29]$ /opt/module/mysql-5.7.29/support-files/mysql.server start
Starting MySQL.
8.检查mysql是否启动成功 执行命令:ps -ef | grep mysql 查询mysql进程,如下图所示则成功
[hadoop@gyh101 mysql-5.7.29]$ ps -ef | grep mysql
hadoop 3223 1 0 12:31 pts/0 00:00:00 /bin/sh /opt/module/mysql-5.7.29/bin/mysqld_safe --datadir=/opt/module/mysql-5.7.29/data --pid-file=/opt/module/mysql-5.7.29/data/gyh101.pid
hadoop 3314 3223 0 12:31 pts/0 00:00:00 /opt/module/mysql-5.7.29/bin/mysqld --basedir=/opt/module/mysql-5.7.29 --datadir=/opt/module/mysql-5.7.29/data --plugin-dir=/opt/module/mysql-5.7.29/lib/plugin --log-error=gyh101.err --pid-file=/opt/module/mysql-5.7.29/data/gyh101.pid
hadoop 5559 2958 0 12:32 pts/0 00:00:00 grep mysql
如果启动时出现如下提示信息
Starting MySQL... ERROR! The server quit without updating PID file
查看是否存在mysql和mysqld的服务,如果存在,则结束进程,再重新执行启动命令
#查询服务
ps -ef|grep mysql
ps -ef|grep mysqld
#结束进程
kill -9 PID
#启动服务
/usr/local/mysql/support-files/mysql.server start
9.添加软连接,并重启mysql服务
[hadoop@gyh101 mysql-5.7.29]$ sudo ln -s /opt/module/mysql-5.7.29/support-files/mysql.server /etc/init.d/mysql
[sudo] password for hadoop:
[hadoop@gyh101 mysql-5.7.29]$ sudo ln -s /opt/module/mysql-5.7.29/bin/mysql /usr/bin/mysql
[hadoop@gyh101 mysql-5.7.29]$ service mysql restart
Shutting down MySQL.. [确定]
Starting MySQL.
10.登录mysql,修改密码为123456(密码为步骤4生成的临时密码)
[hadoop@gyh101 mysql-5.7.29]$ mysql -u root -p
Enter password:
mysql> set password for root@localhost = password('123456');
11.开放远程连接
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> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
12.设置开机自动启动
1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost /]# cp /opt/module/mysql-5.7.29/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost /]# chkconfig --add mysqld
4、显示服务列表
[root@localhost /]# chkconfig --list
13.之后mysql服务操作如下:
service mysql start:开启服务
service mysql stop:关闭服务
service mysql restart:重启服务
[hadoop@gyh101 mysql-5.7.29]$ service mysql start
Starting MySQL.
[hadoop@gyh101 mysql-5.7.29]$ service mysql stop
Shutting down MySQL.. [确定]
[hadoop@gyh101 mysql-5.7.29]$ service mysql restart
Shutting down MySQL.. [确定]
Starting MySQL.