CentOS MySQL5.5编译安装

SKY RING 521 0

准备工作:

CentOS的系统,MySQL的安装包(也可在系统在线下载)

实验环境:腾讯云centos7.2 X64  ,  mysql-5.5.54

描述:源码下载目录/src/;安装目录/usr/local/mysql/;目录可根据自己及的需求自 定义

一,远程连接到Linux的服务器,

二,创建MySQL的用户及所属的MySQL组不允许登录,在线下载MySQL的源码包,并解压,

  • 创建mysql用户及组不允许登录,可以使用cat / etc / passwd命令查看下用户及组是否创建成功;
    groupadd mysql
    useradd -g mysql mysql -M -s /sbin/nologin 
  • 我这里创建/ SRC /目录;
    mkdir -p /src
    cd /src/ 

    如下图:

  • CentOS MySQL5.5编译安装
  • 下载解压;
    wget https://cdn.mysql.com//archives/mysql-5.5/mysql-5.5.54.tar.gz
    
    
    tar -zxvf mysql-5.5.54.tar.gz 

    CentOS MySQL5.5编译安装

  • 进入解压目录;
    cd mysql-5.5.54 

    CentOS MySQL5.5编译安装

重要:安装编译时所依赖的库和软件;

yum install cmake ncurses-devel gcc-c++ -y 

CentOS MySQL5.5编译安装

CentOS MySQL5.5编译安装

三,预编译参数:(编译参数将在后面详解也可到官方查看)

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DMYSQL_USER=mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_DEBUG=0 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \ 

CentOS MySQL5.5编译安装

CentOS MySQL5.5编译安装

如果你在cmake编译时报错需要删除编译缓存,修复错误后再次重新编译,rm -rf CMakeCache.txt

安装:(此时根据机器大概时间10-20分钟)

make && make install 

CentOS MySQL5.5编译安装

四,初始化数据库:

  • 进入初始化目录;
    cd /usr/local/mysql/scripts/ 
  • 指定数据目录,安装目录,用户;(注意此处为一条命令开头有个点)
    ./mysql_install_db --datadir=/usr/local/mysql/data/ --basedir=/usr/local/mysql/ --user=mysql 

    CentOS MySQL5.5编译安装

五,测试启动下我们的MySQL的:

  • 进入启动脚本目录;
    cd /usr/local/mysql/support-files/ 
  • 运行启动脚本;
    ./mysql.server start 
  • 此时将会报错;(将/etc/my.cnf中文件删除这里是因为系统默认了启动文件将其删除即可解决,再次运行启动脚本)
    rm - rf /etc/my.cnf 

CentOS MySQL5.5编译安装

现在我们登录的MySQL,它提示语法错误将安装目录的下的箱里面的MySQL的复制到的/ usr /斌/下面可解决,(也可加入全局变量)再次登录的MySQL已经进来了;

cd /usr/local/mysql/bin/

cp mysql /usr/bin/ 

CentOS MySQL5.5编译安装

六,设置MySQL的安全:

cd /src/mysql-5.5.54/scripts/

./mysql_secure_installation 

CentOS MySQL5.5编译安装

这里详细解释安全不作为命令使用:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
  SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):【这里直接回车默认数据库无密码】
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【询问是否设置root密码输入y】
New password:             【输入您想设置的新密码】          
Re-enter new password:    【重新输入新密码,注意这里输入密码的部分将不显示密码】
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【删除匿名用户,输入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]y

... Success!

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【删除测试数据库,这里输入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【询问我们现在重新加载权限表,这里输入y】
... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL! 

CentOS MySQL5.5编译安装

这时我们使用命令登录MySQL的:【 - P后面也可直接输密码】

mysql -uroot -p 

七,配置的my.cnf到安装目录的等下面当然这个文件可多地方配置并非只有此处;(注意此处复制的文件我-huge.cnf)

mkdir -p /usr/local/mysql/etc

cd /usr/local/mysql/support-files

cp my-huge.cnf ../etc/my.cnf 

CentOS MySQL5.5编译安装

八,设置MySQL的系统命令启动和开机启动如下图;

  • 复制安装目录下的启动脚本到/etc/init.d/中命名为mysqld的;
    cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 
  • 设置开机启动;
    chmod +x /etc/init.d/mysqld
    
    
    chkconfig --add mysqld 
  • 下列命令顺序;(启动,停止,重启,状态)
    systemctl start mysqld
    systemctl stop mysqld
    systemctl restart mysqld
    systemctl status mysqld 
  • 可使用的grep或netstat的命令查看;
    ps -ef |grep mysqld
    
    
    netstat -ntlp 

    CentOS MySQL5.5编译安装

MySQL的的基本安装和设置已经完成,后续知识大家自行博学。

打赏
发表评论
表情 图片 链接 代码

分享
微信
微博
QQ

站点已稳定运行: | 耗时 0.234 秒 | 查询 30 次 | 内存 18.17 MB