二进制包安装MySQL数据库

格式说明:

输入的命令

蓝色字体:注释

×××背景:重要

小标题:底白字


正文:

1.1二进制包安装MySQL数据库

1.1.1 安装前准备(规范)

1.[root@localhost ~]# mkdir -p /home/zhurui/tools  ##创建指定工具包存放路径

2.[root@localhost ~]#wget http://dev.mysql.com/get/Downloads//MySQL-5.5/mysql-5.5.32-linux2.6-x86_64.gz  #下载二进制包 

3.[root@localhost ~]# cp mysql-5.5.32-linux2.6-x86_64.tar.gz  /home/zhurui/tools

4.[root@localhost ~]# cd /home/zhurui/tools

5.[root@localhost tools]# ll

total 182352

-rw-r--r--. 1 root root 186722932 Oct  6 22:55 mysql-5.5.32-linux2.6-x86_64.tar.gz

6.[root@localhost tools]# tar xf mysql-5.5.32-linux2.6-x86_64.tar.gz   ##解压Mysql 

7.[root@localhost tools]# useradd -s /sbin/nologin -M mysql  ##创建mysql用户 

8.[root@localhost tools]# id mysql

uid=501(mysql) gid=501(mysql) groups=501(mysql)

9.[root@localhost ~]# mkdir /application/

10[root@localhost home]# mv /home/zhurui/tools/mysql-5.5.32-linux2.6-x86_64 /application/mysql-5.5.32  

11.[root@localhost tools]# ll /application/

total 4

drwxr-xr-x. 13 root root 4096 Dec 13 14:31 mysql-5.5.32

12.[root@localhost tools]# ln -s /application/mysql-5.5.32/ /application/mysql  ##设置软链接

13.[root@localhost tools]# ll /application/

total 4

lrwxrwxrwx.  1 root root   26 Dec 13 14:39 mysql -> /application/mysql-5.5.32/

drwxr-xr-x. 13 root root 4096 Dec 13 14:31 mysql-5.5.32

15.[root@localhost tools]# ll /application/mysql/

total 76

drwxr-xr-x.  2 root root   4096 Dec 13 14:31 bin

-rw-r--r--.  1 7161 wheel 17987 Jun 19  2013 COPYING

drwxr-xr-x.  3 root root   4096 Dec 13 14:31 data

drwxr-xr-x.  2 root root   4096 Dec 13 14:30 docs

drwxr-xr-x.  3 root root   4096 Dec 13 14:31 include

-rw-r--r--.  1 7161 wheel  7470 Jun 19  2013 INSTALL-BINARY

drwxr-xr-x.  3 root root   4096 Dec 13 14:31 lib

drwxr-xr-x.  4 root root   4096 Dec 13 14:31 man

drwxr-xr-x. 10 root root   4096 Dec 13 14:31 mysql-test

-rw-r--r--.  1 7161 wheel  2496 Jun 19  2013 README

drwxr-xr-x.  2 root root   4096 Dec 13 14:31 scripts

drwxr-xr-x. 27 root root   4096 Dec 13 14:31 share

drwxr-xr-x.  4 root root   4096 Dec 13 14:31 sql-bench

drwxr-xr-x.  3 root root   4096 Dec 13 14:31 support-files

1.1.2 初始化数据库

 [root@Mysql_server tools]# /application/mysql/scripts/mysql_install_db --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql  ##初始化数据库

Installing MySQL system tables...

OK       #初始化成功的标志

Filling help tables...

OK                        #初始化成功的标志

[root@Mysql_server tools]# ll /application/mysql/data/  ##查看初始化结果

total 12

drwx------. 2 mysql root  4096 Dec 13 14:45 mysql

drwx------. 2 mysql mysql 4096 Dec 13 14:45 performance_schema

drwxr-xr-x. 2 mysql root  4096 Dec 13 14:31 test

1.1.3 授权Mysql管理数据库文件

[root@localhost ~]# chown -R mysql.mysql /application/mysql/

[root@localhost ~]# ll /application/mysql

lrwxrwxrwx. 1 mysql mysql 26 Dec 13 14:39 /application/mysql -> /application/mysql-5.5.32/

1.1.4 生成Mysql配置文件

[root@Mysql_server tools]# \cp /application/mysql/support-files/my-small.cnf    /etc/my.cnf

#配置文件为/etc/my.cnf

1.1.5 配置启动Mysql

1 [root@localhost tools]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe /application/mysql/support-files/mysql.server 

2 [root@localhost tools]# cp /application/mysql/support-files/mysql.server      /etc/init.d/mysqld  ##将生成的启动脚本拷贝到init.d目录下

3 [root@localhost tools]# chmod +x /etc/init.d/mysqld 

1.1.6 启动Mysql

1 [root@localhost tools]# lsof -i :3306  ##查询Mysql服务是否开启

2 [root@localhost tools]# /etc/init.d/mysqld start  ##启动Mysql服务

 Starting MySQL.... SUCCESS! 

3 [root@localhost tools]# lsof -i :3306

 COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

 mysqld  2235 mysql   10u  IPv4  22761      0t0  TCP *:mysql (LISTEN)

1.1.7 配置环境变量

方法1

[root@localhost tools]# cp /application/mysql/bin/*      /usr/local/sbin/ ##方法1

方法2

1 [root@localhost tools]# tail -1 /etc/profile 

PATH="/application/mysql/bin:$PATH"   ##尾部添加如下行

2 [root@localhost tools]# source /etc/profile    ##使得配置生效

1.1.8 设置及更改密码

1 [root@localhost tools]# mysqladmin -uroot password 123456   

2 [root@localhost tools]# mysqladmin -uroot -p123456  password  新密码

2.1 登录数据库

[root@localhost tools]# mysql -uroot -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 8

Server version: 5.5.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, 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> #数据库登录成功

感谢原作者:http://www.cnblogs.com/hackerer/p/5294092.html