说明:mysql的版本:mysql-5.5.21-linux2.6-x86_64.tar.gz

1.添加傀儡用户

[root@web01 ~]# useradd  -s  /sbin/nologin  -M  mysql

[root@web01 ~]# id  mysql

uid=502(mysql) gid=502(mysql) 组=502(mysql)

[root@web01 ~]# 

2.上传二进制包(目录没有自己创建,这是安装nginx的时候创建的目录,都放在一起)

[root@web01 ~]# cd /home/oldboy/tools/

[root@web01 tools]# ls

nginx-1.6.3  nginx-1.6.3.tar.gz

[root@web01 tools]# rz 

rz waiting to receive.

 zmodem trl+C 

  100%  181708 KB 8652 KB/s 00:00:21       0 Errorss86_64.tar.gz...

[root@web01 tools]# ls

mysql-5.5.21-linux2.6-x86_64.tar.gz  nginx-1.6.3  nginx-1.6.3.tar.gz

[root@web01 tools]# 

[root@web01 tools]# ls

mysql-5.5.21-linux2.6-x86_64.tar.gz  nginx-1.6.3  nginx-1.6.3.tar.gz

[root@web01 tools]# 

3.解压二进制包

[root@web01 tools]# tar xf mysql-5.5.21-linux2.6-x86_64.tar.gz 

[root@web01 tools]# ls

mysql-5.5.21-linux2.6-x86_64         nginx-1.6.3

mysql-5.5.21-linux2.6-x86_64.tar.gz  nginx-1.6.3.tar.gz

[root@web01 tools]# 

4.二进制包不用编译,把解压的二进制包放在规定的位置,做做软连接,方便管理

[root@web01 tools]# mv mysql-5.5.21-linux2.6-x86_64  /application/mysql-5.5.32

[root@web01 tools]# ln -s /application/mysql-5.5.32 /application/mysql

[root@web01 tools]# ll /application/mysql

lrwxrwxrwx 1 root root 25 5月  11 16:32 /application/mysql -> /application/mysql-5.5.32

[root@web01 tools]# 

5.初始化数据库(两个OK正确的标志)

--basedir=/application/mysql/   指定安装的目录

datadir=/application/mysql/data/  指定数据存放的位置

--user=mysql  指定用户

[root@web01 ~]# /application/mysql/scripts/mysql_install_db  --basedir=/application/mysql/  --datadir=/application/mysql/data/ --user=mysql

Installing MySQL system tables...

OK

Filling help tables...

OK

To start mysqld at boot time you have to copy

support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !

To do so, start the server, then issue the following commands:

/application/mysql//bin/mysqladmin -u root password 'new-password'

/application/mysql//bin/mysqladmin -u root -h web01 password 'new-password'

Alternatively you can run:

/application/mysql//bin/mysql_secure_installation

which will also give you the option of removing the test

databases and anonymous user created by default.  This is

strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

cd /application/mysql/ ; /application/mysql//bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

cd /application/mysql//mysql-test ; perl mysql-test-run.pl

Please report any problems with the /application/mysql//scripts/mysqlbug script!

[root@web01 ~]# 

6.授权mysql管理数据库文件

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

[root@web01 ~]#

7.生成mysql的配置文件

[root@web01 support-files]# pwd

/application/mysql/support-files

[root@web01 support-files]# cp  my-small.cnf  /etc/my.cnf

cp:是否覆盖"/etc/my.cnf"? y

[root@web01 support-files]# 

8修改mysql启动的文件路径(默认是:/application/mysql/bin/mysqld_safe 

[root@web01 ~]# cat /application/mysql/bin/mysqld_safe 

[root@web01 local]# sed -i 's#/usr/local/mysql#/application/mysql#g' /application/mysql/bin/mysqld_safe 

[root@web01 local]# 

9.后台启动mysql

[root@web01 local]# /application/mysql/bin/mysqld_safe &

[root@web01 local]# lsof -i:3306

COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

mysqld  1712 mysql   10u  IPv4  10536      0t0  TCP *:mysql (LISTEN)

[root@web01 local]#

10.mysql的命令都在/application/mysql/bin/  为了不带路径执行mysql的命令,调整PATH路径

①把mysql的命令的路径加到PATH路径下(建议使用这一种)

[root@web01 ~]# PATH="/application/mysql/bin:$PATH"

spacer.gif

②把mysql的命令拷贝到已知的PATH路径下(上课老师用的这一种,正确)

[root@web01 bin]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

[root@web01 bin]# cp  /application/mysql/bin/*  /usr/local/sbin/

[root@web01 bin]# which  mysql

/usr/local/sbin/mysql

[root@web01 bin]# 

11.调整启动的方式

[root@web01 ~]#cp  /application/mysql/support-files/mysql.server   /etc/init.d/mysqld

[root@web01 ~]#  sed -i 's#/usr/local/mysql#/application/mysql#g' /etc/init.d/mysqld  

[root@web01 ~]# chmod +x /etc/init.d/mysqld

[root@web01 ~]# 

12.测试启动顺序的调整(生产环境不要用pkill

[root@web01 ~]# killall  mysqld

[root@web01 ~]# lsof -i:3306

[root@web01 ~]# 

[root@web01 ~]# /etc/init.d/mysqld  start

Starting MySQL.. SUCCESS! 

[root@web01 ~]# 

13.加入开机自启服务

[root@web01 ~]# chkconfig mysqld on 

[root@web01 ~]# chkconfig --list  mysqld

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@web01 ~]# 

14.修改mysql的密码(默认是没有密码的)

[root@web01 ~]# mysqladmin -uroot password "123456"

测试:

[root@web01 ~]# mysql -uroot  -p123456

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

Your MySQL connection id is 4

Server version: 5.5.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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> 

15.mysql更改已知的密码

[root@web01 ~]# mysqladmin  -uroot -p123456 password "oldboy"

[root@web01 ~]# mysql -uroot -p123456

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@web01 ~]# mysql -uroot -poldboy

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

Your MySQL connection id is 7

Server version: 5.5.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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> 


16.交互式给密码(这样在history历史记录没有办法看到密码)

[root@web01 ~]# mysqladmin  -uroot -p123456 password "oldboy"

[root@web01 ~]# mysql -uroot -p123456

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

[root@web01 ~]# mysql -uroot -poldboy

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

Your MySQL connection id is 7

Server version: 5.5.21 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, 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> 


j_0057.gifj_0057.gifj_0057.gif