首页 > 数据库 >安装数据库CentOS 7.6+MySQL5.6

安装数据库CentOS 7.6+MySQL5.6

时间:2023-03-06 13:44:44浏览次数:45  
标签:CentOS local MySQL5.6 iZbp16tff364has58lxi61Z 7.6 usr mysql MySQL root

1. 安装编译源码所需的工具和库

root@iZbp16tff364has58lxi61Z ~]# yum -y install gcc gcc-c++ ncurses-devel perl
root@iZbp16tff364has58lxi61Z ~]# yum -y groupinstall "Development tools" "Desktop Platform Development" "Server Platform Development"
root@iZbp16tff364has58lxi61Z ~]# yum -y install cmake
root@iZbp16tff364has58lxi61Z ~]# yum -y install openssl openssl-devel ncurses ncurses-devel

2. 删除系统自带的MySQL
root@iZbp16tff364has58lxi61Z ~]# rpm -qa | grep mariadb
root@iZbp16tff364has58lxi61Z ~]# yum -y remove mari*
root@iZbp16tff364has58lxi61Z ~]# rm -rf /var/lib/mysql/*
root@iZbp16tff364has58lxi61Z ~]# rpm -qa | grep mariadb

3. 创建数据库目录、mysql用户,并修改数据目录的属主
root@iZbp16tff364has58lxi61Z ~]# mkdir -pv /mydata/data
root@iZbp16tff364has58lxi61Z ~]# useradd -s /sbin/nologin mysql
root@iZbp16tff364has58lxi61Z ~]# chown -R mysql:mysql /mydata/data/

4. 下载MySQL源码tar包解压
root@iZbp16tff364has58lxi61Z ~]# cd /usr/local/src
root@iZbp16tff364has58lxi61Z src]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz(若没有则下载)
root@iZbp16tff364has58lxi61Z src]# tar -zxvf mysql-5.6.51-linux-glibc2.12-x86_64.tar.gz -C /usr/local/

5. 设置编译参数,编译,安装(不走这步骤)
root@iZbp16tff364has58lxi61Z src]# cd /usr/local/mysql-5.6.37
root@iZbp16tff364has58lxi61Z mysql-5.6.37]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/mydata/data/ -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
root@iZbp16tff364has58lxi61Z mysql-5.6.37]# make
root@iZbp16tff364has58lxi61Z mysql-5.6.37]# make install

6.初始化数据库
[root@iZbp16tff364has58lxi61Z mysql-5.6.51]# cd /usr/local/
[root@iZbp16tff364has58lxi61Z local]# mv mysql-5.6.51-linux-glibc2.12-x86_64/ mysql/
[root@iZbp16tff364has58lxi61Z local]# cd /usr/local/mysql/scripts/
[root@iZbp16tff364has58lxi61Z local]# chown -R mysql:mysql /usr/local/mysql/data/
[root@iZbp16tff364has58lxi61Z local]# cd /usr/local/mysql/scripts/
[root@iZbp16tff364has58lxi61Z scripts]# yum install libaio*
[root@iZbp16tff364has58lxi61Z scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

7. 复制MySQL服务启动脚本
[root@iZbp16tff364has58lxi61Z scripts]# cd /usr/local/mysql/support-files/
[root@iZbp16tff364has58lxi61Z support-files]# cp mysql.server /etc/init.d/mysqld
[root@iZbp16tff364has58lxi61Z support-files]# chmod a+x /etc/init.d/mysqld

8. 配置MySQL环境变量
[root@iZbp16tff364has58lxi61Z support-files]# vi /etc/profile

在/etc/profile文件末尾添加如下两行

export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH

添加完成后退出编辑,执行如下命令使配置生效
[root@iZbp16tff364has58lxi61Z support-files]# source /etc/profile

9. 复制MySQL配置文件
[root@iZbp16tff364has58lxi61Z support-files]# cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf

在my.cnf文件中增加如下配置,添加到[mysqld]之后:
[root@iZbp16tff364has58lxi61Z support-files]# vi /etc/my.cnf

innodb_file_per_table = 1
datadir = /usr/local/mysql/data/
port = 3306
user = mysql
server_id = 1
socket = /tmp/mysql.sock

10. 启动MySQL服务

[root@iZbp16tff364has58lxi61Z support-files]# service mysqld start

执行如下命令查看MySQL服务是否正常运行,显示is running...表示正在运行。
[root@iZbp16tff364has58lxi61Z support-files]# service mysqld status
 SUCCESS! MySQL running (1971)

11. 设置数据库的root用户密码
[root@iZbp16tff364has58lxi61Z support-files]# /usr/local/mysql/bin/mysql_secure_installation
备注:安装后MySQL的默认密码为空,所以在输入当前密码时直接回车即可。
回车后实例:
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.

Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


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
 ... 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...

12. 设置MySQL服务开机自启动
添加MySQL到开机自启动服务
[root@iZbp16tff364has58lxi61Z support-files]# chkconfig --add mysqld

设置MySQL服务开机自启动
[root@iZbp16tff364has58lxi61Z support-files]# chkconfig mysqld on

查看是否设置成功,执行如下命令查询,如果显示结果与以下结果一致,表示已完成设置开机自启动MySQL
[root@iZbp16tff364has58lxi61Z support-files]# chkconfig --list | grep mysqld
mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

13. 连接数据库
[root@centos65 bin]# mysql -uroot -p

标签:CentOS,local,MySQL5.6,iZbp16tff364has58lxi61Z,7.6,usr,mysql,MySQL,root
From: https://www.cnblogs.com/IceSparks/p/17183537.html

相关文章

  • centos7.9系统禁用selinux脚本
    临时关闭setenforcepermissive永久关闭配置文件路径/etc/sysconfig/selinux修改配置项SELINUX=enforcing为SELINUX=disabledsed-i's/SELINUX=enforcing/'SEL......
  • CentOS 升级内核的三种方式(yum/rpm/源码)
    CentOS升级内核的三种方式(yum/rpm/源码)在CentOS使用过程中,难免需要升级内核,但有时候因为源码编译依赖问题,不一定所有程序都支持最新内核版本,所以以下将介绍三种升级内......
  • dell 5090装centos
    真实机安装完centos7版本后,会发现没有网卡,只有lo口。这是因为有些真实机安装了centos系统后没有网卡驱动。需要我们去网上下载一个linux版本的驱动包来安装。先查看我的网......
  • centos7离线部署ansible并通过ansible批量修改用户密码
    centos7离线部署ansible并通过ansible批量修改用户密码找台可以联网的机器下载好程序包,上传到对应主机mkdir/app/ansible-p#下载bzip2yuminstall-ybzip2--downlo......
  • centOS端口映射命令
    初始化端口映射环境:echo1>/proc/sys/net/ipv4/ip_forwardiptables-tnat-APOSTROUTING-jMASQUERADE映射端口:iptables-tnat-APREROUTING-d172.16.0.4-ptcp......
  • CentOS下的挂载磁盘和逻辑卷
    挂载分区#查看磁盘情况,找到未挂载的磁盘名fdisk-l#找新挂载的磁盘进行分区2Gfdisk/dev/sdb#根据指引#n新建分区#p创建主分区#1创建第几个分区#输入磁盘阵列......
  • centos7在线扩容根分区LVM
    背景:现已有lvm根分区,不能满足业务需求,在业务不下线的情况下对/分区扩容思路:创建新分区=>创建物理卷=>加入卷组=>扩容1、找到要扩容的分区2、找到新添加的磁盘......
  • 使用ELRepo升级CentOS内核
    在腾讯云中部署了一些服务器,操作系统使用的是CentOS7.6,但是其默认内核版本较低,现使用ELRepo对CentOS的内核进行升级。操作环境服务器:腾讯云轻量应用服务器操作系统:Cent......
  • python 安装最新版3.11.2 for centos
    目录Python安装前的准备参考官方文档openssl下载地址openssl安装python的安装遇到的一些坑Python安装前的准备sudoyumupdate&&sudoyuminstall-yopenssl-deve......
  • centos8本地仓库
    centos8centos8除了需要创建repodata还需要创建modularmetadata,如果只有repodata就会报错:Noavailablemodularmetadataformodularpackage1.安装modularmetadata......