说明:mysql的版本:mysql-5.5.21-linux2.6-x86_64.tar.gz
1.添加傀儡用户
[[email protected] ~]# useradd -s /sbin/nologin -M mysql
[[email protected] ~]# id mysql
uid=502(mysql) gid=502(mysql) 组=502(mysql)
[[email protected] ~]#
2.上传二进制包(目录没有自己创建,这是安装nginx的时候创建的目录,都放在一起)
[[email protected] ~]# cd /home/oldboy/tools/
[[email protected] tools]# ls
nginx-1.6.3 nginx-1.6.3.tar.gz
[[email protected] tools]# rz
rz waiting to receive.
zmodem trl+C
100% 181708 KB 8652 KB/s 00:00:21 0 Errorss86_64.tar.gz...
[[email protected] tools]# ls
mysql-5.5.21-linux2.6-x86_64.tar.gz nginx-1.6.3 nginx-1.6.3.tar.gz
[[email protected] tools]#
[[email protected] tools]# ls
mysql-5.5.21-linux2.6-x86_64.tar.gz nginx-1.6.3 nginx-1.6.3.tar.gz
[[email protected] tools]#
3.解压二进制包
[[email protected] tools]# tar xf mysql-5.5.21-linux2.6-x86_64.tar.gz
[[email protected] 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
[[email protected] tools]#
4.二进制包不用编译,把解压的二进制包放在规定的位置,做做软连接,方便管理
[[email protected] tools]# mv mysql-5.5.21-linux2.6-x86_64 /application/mysql-5.5.32
[[email protected] tools]# ln -s /application/mysql-5.5.32 /application/mysql
[[email protected] tools]# ll /application/mysql
lrwxrwxrwx 1 root root 25 5月 11 16:32 /application/mysql -> /application/mysql-5.5.32
[[email protected] tools]#
5.初始化数据库(两个OK正确的标志)
--basedir=/application/mysql/ 指定安装的目录
datadir=/application/mysql/data/ 指定数据存放的位置
--user=mysql 指定用户
[[email protected] ~]# /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!
[[email protected] ~]#
6.授权mysql管理数据库文件
[[email protected] ~]# chown -R mysql.mysql /application/mysql/
[[email protected] ~]#
7.生成mysql的配置文件
[[email protected] support-files]# pwd
/application/mysql/support-files
[[email protected] support-files]# cp my-small.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
[[email protected] support-files]#
8修改mysql启动的文件路径(默认是:/application/mysql/bin/mysqld_safe )
[[email protected] ~]# cat /application/mysql/bin/mysqld_safe
[[email protected] local]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /application/mysql/bin/mysqld_safe
[[email protected] local]#
9.后台启动mysql
[[email protected] local]# /application/mysql/bin/mysqld_safe &
[[email protected] local]# lsof -i:3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 1712 mysql 10u IPv4 10536 0t0 TCP *:mysql (LISTEN)
[[email protected] local]#
10.mysql的命令都在/application/mysql/bin/ 为了不带路径执行mysql的命令,调整PATH路径
①把mysql的命令的路径加到PATH路径下(建议使用这一种)
[[email protected] ~]# PATH="/application/mysql/bin:$PATH"
②把mysql的命令拷贝到已知的PATH路径下(上课老师用的这一种,正确)
[[email protected] bin]# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[[email protected] bin]# cp /application/mysql/bin/* /usr/local/sbin/
[[email protected] bin]# which mysql
/usr/local/sbin/mysql
[[email protected] bin]#
11.调整启动的方式
[[email protected] ~]#cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# sed -i ‘s#/usr/local/mysql#/application/mysql#g‘ /etc/init.d/mysqld
[[email protected] ~]# chmod +x /etc/init.d/mysqld
[[email protected] ~]#
12.测试启动顺序的调整(生产环境不要用pkill)
[[email protected] ~]# killall mysqld
[[email protected] ~]# lsof -i:3306
[[email protected] ~]#
[[email protected] ~]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
[[email protected] ~]#
13.加入开机自启服务
[[email protected] ~]# chkconfig mysqld on
[[email protected] ~]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[[email protected] ~]#
14.修改mysql的密码(默认是没有密码的)
[[email protected] ~]# mysqladmin -uroot password "123456"
测试:
[[email protected] ~]# 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更改已知的密码
[[email protected] ~]# mysqladmin -uroot -p123456 password "oldboy"
[[email protected] ~]# mysql -uroot -p123456
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
[[email protected] ~]# 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历史记录没有办法看到密码)
[[email protected] ~]# mysqladmin -uroot -p123456 password "oldboy"
[[email protected] ~]# mysql -uroot -p123456
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)
[[email protected] ~]# 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>