博文摘要
接着介绍另外一种安装方式对mysql进行安装(有兴趣的读者可以浏览 Linux安装Mysql5.7.X(一),两者区别不大,可以根据自己的偏好),本文针对mysql安装到指定目录下(本文安装在/software/msql),大部分网上都是安装在/usr/local下的!
本文使用mysql-xxx.tar.gz数据包的范式进行安装、配置操作,话不多说,直接上干货
一、准备阶段
1、查看本机是否有已经安装mysql(如果没有安装,此步骤可以跳过)
rpm -qa | grep mysql
如果执行该命令,没有任何显示,恭喜你,你的机子吗,诶呦安装mysql数据库,直接可以跳过进行【步骤1】了!
当然,本人针对大部分读者,包含已经安装过的机子!!
[root@VM-0-16-centos /]# rpm -qa | grep mysql
mysql-community-client-8.0.23-1.el7.x86_64
mysql80-community-release-el7-3.noarch
mysql-community-libs-compat-8.0.23-1.el7.x86_64
(笔者的机子安装了mysql8.0版本,先进行卸载)
[root@VM-0-16-centos /]# rpm -e --nodeps mysql-community-client-8.0.23-1.el7.x86_64
[root@VM-0-16-centos /]# rpm -e --nodeps mysql80-community-release-el7-3.noarch
[root@VM-0-16-centos /]# rpm -e --nodeps mysql-community-libs-compat-8.0.23-1.el7.x86_64
# 查看是否还有mysql残留
[root@VM-0-16-centos /]# rpm -qa | grep mysql
[root@VM-0-16-centos /]#
如果你执行 rpm -qa | grep mysql后没有任何记录,表示你的机子已经没有mysql的余孽了!
2、创建文件夹
# 切换到根目录下
cd /
# 创建software目录
mkdir software
# 创建mysql目录
cd software
mkdir mysql
基本准备工作已经告一阶段!
二、mysql安装包下载、解压
本文以mysql-5.7.24_64bit版本为例,下载软件包,当然笔者也可以登录mysql官网进行手动下载,然后通过xftp等工具上传到服务器上,具体方式根据自己场景进行!
# 文件包下载
[root@VM-0-16-centos software]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
# 文件包解压
[root@VM-0-16-centos software]# tar zxf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
[root@VM-0-16-centos software]# ls
mysql mysql-5.7.24-linux-glibc2.12-x86_64 mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mysql-5.7.24-linux-glibc2.12-x86_64就是我们所需要的使用的文件了!
可以把mysql-5.7.24-linux-glibc2.12-x86_64下的所有文件移动到mysql下,或者命名为mysql,这个操作不是必须的,仅仅是配合本文所提到的以/software/mysql为安装路径所做的准备而已!
三、mysql安装、配置
1、创建data目录
[root@VM-0-16-centos /]# mkdir /software/mysql/data
2、更改mysql目录下所有的目录及文件夹所属的用户组和用户,以及权限
[root@VM-0-16-centos /]# chown -R mysql:mysql /software/mysql/data/
[root@VM-0-16-centos /]# chmod -R 755 /software/mysql
3、编译安装并初始化mysql
[root@VM-0-16-centos bin]#
[root@VM-0-16-centos bin]# ./mysqld --initialize --user=mysql --datadir=/software/mysql/data --basedir=/software/mysql
2021-02-27T03:33:44.349386Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-02-27T03:33:44.673069Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-02-27T03:33:44.796203Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-02-27T03:33:44.866274Z 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: 983b4a80-78ac-11eb-85c4-5254001d6fe4.
2021-02-27T03:33:44.872075Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-02-27T03:33:44.872531Z 1 [Note] A temporary password is generated for root@localhost: kiaon+9JfkDk
如果读者在操作过程中没有遇到该异常,直接跳过该步骤即可
问题:./mysqld: error while loading shared libaraies: libaio.so.l: xannot open shared object file: No such file or directory
出现该问题首先检查该链接库文件有没有安装使用 命令进行核查
[root@VM-0-16-centos /]# rpm -qa|grep libaio
[root@VM-0-16-centos /]#
运行命令后发现系统中无该链接库文件
[root@VM-0-16-centos /]# yum install libaio-devel.x86_64
必须记住初始化输出日志的数据库管理员临时密码 [Note] A temporary password is generated for root@localhost: kiaon+9JfkDk
4、添加或者修改my.cnf文件
# 编辑文件
vim /etc/my.cnf
如果打开的文件为空(没有任何数据),表示没有该文件,直接编辑即可
# 配置文件内容
[mysqld]
basedir=/software/mysq
datadir=/software/mysql/data
port=3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=600
innodb_file_per_table=1
lower_case_table_names=1
character_set_server=utf8
内容说明:
lower_case_table_names:是否区分大小写,1表示存储时表名为小写,操作时不区分大小写;0表示区分大小写;不能动态设置,修改后,必须重启才能生效:
character_set_server:设置数据库默认字符集,如果不设置默认为latin1
innodb_file_per_table:是否将每个表的数据单独存储,1表示单独存储;0表示关闭独立表空间,可以通过查看数据目录,查看文件结构的区别;
5、测试启动mysql服务器
[root@VM-0-16-centos ]# /software/mysql/support-files/mysql.server start
查看运行状态
[root@VM-0-16-centos ]# ps -ef|grep mysql
到此,说明mysql已经成功启动了!
但是,有没有发现在启动过程中【/software/mysql/support-files/mysql.server start】是不是很恶心!不怕,下载咱们一块适配一下,直接使用service mysql start的方式启动,这是不是感觉很清爽!
三、添加软连接
添加软连接,直接使用servic方式对mysql操作,此步类似windows环境下安装jdk添加环境变量一样!!
# 添加软连接
[root@VM-0-16-centos ]# ln -s /software/mysql/support-files/mysql.server /etc/init.d/mysql
[root@VM-0-16-centos ]# ln -s /software/mysql/bin/mysql /usr/bin/mysql
# 启动服务器
[root@VM-0-16-centos ]# service mysql restart
四、修改密码
由于安装mysql时自动生成的临时密码比较难记,此步骤修改一下登录密码!此步骤也是非必要的,具体看读者自己喽!
# 数据库登录
[root@VM-0-16-centos ]# mysql -uroot -pkiaon+9JfkDk
# 设置密码
[root@VM-0-16-centos ]# set password for root@localhost = password('新的密码');
五、开放远程连接
避免在使用客户端工具连接数据库服务器失败的情况下,需要开启服务器远程连接限制
# 切换数据库
[root@VM-0-16-centos ]# use mysql;
# 开放host过滤限制
[root@VM-0-16-centos ]# update user set user.Host='%' where user.User='root';
# 刷新权限
[root@VM-0-16-centos ]# flush privileges;
六、设置开机自动启动
# 1、将服务文件拷贝到init.d下,并重命名为mysql
[root@VM-0-16-centos ]# cp /software/mysql/support-files/mysql.server /etc/init.d/mysqld
# 2、赋予可执行权限
[root@VM-0-16-centos ]# chmod +x /etc/init.d/mysqld
# 3、添加服务
[root@VM-0-16-centos ]# chkconfig --add mysqld
# 4、显示服务列表
[root@VM-0-16-centos ]# chkconfig --list
到此,基本完成操作!如果有不妥地方,欢迎读者进行指正!
--------------------------------------------------------------------------------------
作者:超级字节码
来源:CSDN
原文:https://blog.csdn.net/dgxin_605/article/details/114169806
版权声明:本文为博主原创文章,转载请附上博文链接!
--------------------------------------------------------------------------------------