在centos7的普通用户下二进制安装mysql5.5版本

首将mysql5.5上传到服务器上并改名为mysql,方便操作。我们要将mysql安装在我们的用户目录下,测试名路径和mysql下的目录如下:

[test1@chen mysql]$ pwd
/home/test1/mysql
[test1@chen mysql]$ ls
bin      data  include         lib  mysql-test  scripts  sql-bench
COPYING  docs  INSTALL-BINARY  man  README      share    support-files

我们将support下的my-small.cnf复制到mysql目录下作配置文件并命名为my.cnf。(注意:5.6版本的这个目录下的东西有些不一样,因此就要复制 my-default.cnf 。)

[test1@chen mysql]$ cp ./support-files/my-small.cnf ./my.cnf
[test1@chen mysql]$ ls
bin      docs            lib     mysql-test  share
COPYING  include         man     README      sql-bench
data     INSTALL-BINARY  my.cnf  scripts     support-files

然后我们用 vi 命令编辑修改配置文件,指明客户端和服务端的一些路径并根据自己的需要更改端口,我这里把端口改为3307。(注意:5.6版本的没有 client 如果提示客户端也需要一些路径的话 ,我们给加上就可以。)如下:

# The following options will be passed to all MySQL clients
[client]
#password       = your_password
port            = 3307
socket          = /home/test1/mysql/mysql.sock

# Here follows entries for some specific programs

# The MySQL server
[mysqld]
port            = 3307
socket          = /home/test1/mysql/mysql.sock
basedir         =/home/test1/mysql
datadir         =/home/test1/mysql/data
log-error       = /home/test1/mysql/mysql.log

接下来我们用安装 mysql 的用户对数据库进行初始化了,此时要注意初始化数据库需要依赖包,如果没有安装系统会报错,我们在普通用户下用 sudo 权限安装一下,(注意:5.6版本的就会提示少库,可以网上找一下命令。)安装代码代码如下:

[test1@chen mysql]$ sudo yum -y install libaio-devel
[sudo] password for test1: 
Loaded plugins: fastestmirror
base                                                     | 3.6 kB     00:00     
epel                                                     | 4.3 kB     00:00     
extras                                                   | 3.4 kB     00:00     
updates                                                  | 3.4 kB     00:00     
(1/7): epel/x86_64/group_gz                                | 170 kB   00:00     

接下来初始化数据库(注意5.6版本可能会提示内存不足一系列的原因,我们可以改小一些内存然后在下面的语句中加上默认按自己改的 my.cnf 执行即可):

[test1@chen mysql]$ scripts/mysql_install_db --user=test1 --datadir=/home/test1/mysql/data 
Installing MySQL system tables...
170924 18:43:16 [Note] ./bin/mysqld (mysqld 5.5.52) starting as process 10994 ...
OK
Filling help tables...
170924 18:43:16 [Note] ./bin/mysqld (mysqld 5.5.52) starting as process 11000 ...
OK

出现两个OK就代表成功了,然后我们就可以启动数据库了,启动数据文件是 bin 目录下的 mysqld ,(5.6版本的话,可能会出现一些其他的错误,我们只需要看一下错误日志分析一下就可以了。)代码如下:

[test1@chen mysql]$ ./bin/mysqld --defaults-file=./my.cnf &
[1] 12445
[test1@chen mysql]$ 170924 20:55:17 [Note] ./bin/mysqld (mysqld 5.5.52) starting as process 12445 ...

可以查看下进程看启动了没有,如下就是启动了:

[test1@chen mysql]$ ps -ef|grep mysql
test1    12445 12325  0 20:55 pts/0    00:00:00 ./bin/mysqld --defaults-file=./my.cnf
test1    12495 12325  0 21:03 pts/0    00:00:00 grep --color=auto mysql

然后我们就可以进入数据库啦,按着 my.cnf 执行 bin 目录下的 mysql 文件,如下:

[test1@chen mysql]$ ./bin/mysql --defaults-file=./my.cnf -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.52 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

执行一下,会让输入密码,由于我们没有设置密码,所以密码是空,直接恩 Enter 就可以进来了。如上图,提示我们已经进入数据库了。当然我们可以修改一次密码,(此方法也适用于5.6版本)在 mysql 目录下输入如下代码:

[test1@chen mysql]$ ./bin/mysqladmin --defaults-file=./my.cnf -u root password '12345678'

接着用我们的密码就可以进入数据库啦。

[test1@chen mysql]$ ./bin/mysql --defaults-file=./my.cnf -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.5.52 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> quit
Bye

如果觉得启动服务和进入数据库时输入的命令太长有些麻烦的话,我们可以创建两个脚本文件,我这里用 vi 命令分别创建两个用于启动服务和进入数据库的脚本文件start.sh和goto.sh。代码如下:

[test1@chen mysql]$ vi start.sh

~
~
~

输入 i 进入编辑模式,然后输入:

./bin/mysqld --defaults-file=./my.cnf &

wq 保存退出后。再用 vi 创建goto.sh,并进入编辑模式输入

[test1@chen mysql]$ vi goto.sh

~
~
~
./bin/mysql --defaults-file=./my.cnf -u root -p

保存退出,然后更改这两个文件的权限变成可执行文件就大功告成啦。

[test1@chen mysql]$ ./goto.sh 
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.52 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

这是只是一种方法,这个方法缺点是只能杀进程停止服务,当然我们也可以在网上找一下方法来解决,正所谓条条大路通罗马,还有更好的方法等你去学习哦!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值