使用tar在linux中定制化得安装mysql

在linux中利用tar包,将mysql进行定制化的部署

第一步:将tar包上传到/usr/local目录下。

第二步:检查mysql是否安装,ps -ef | grep mysqld。

第三步:解压tar包,并重命名。

使用tar在linux中定制化得安装mysql

第四步: 创建用户组和用户 mysqladmin

[[email protected] local]# groupadd -g 101 dba
[[email protected] local]# useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin
使用tar在linux中定制化得安装mysql
copy 环境变量配置文件至mysqladmin用户的home目录中,为了以下步骤配置个人环境变量
[[email protected] local]# cp /etc/skel/.* /usr/local/mysql

第五步: 创建mysql配置文件my.cnf

mysql启动时配置文件的查找顺序:
#defualt start: /etc/my.cnf->/etc/mysql/my.cnf->SYSCONFDIR/my.cnf
->$MYSQL_HOME/my.cnf-> --defaults-extra-file->~/my.cnf

[[email protected] mysql]# cd /etc/
[[email protected] etc]# touch my.cnf
[[email protected] etc]# vi my.cnf

使用tar在linux中定制化得安装mysql
使用tar在linux中定制化得安装mysql

第六步:修改my.cnf的权限,用户,用户组

[[email protected] local]# chown mysqladmin:dba /etc/my.cnf
[[email protected] local]# chmod 640 /etc/my.cnf
[[email protected] etc]# ll my.cnf

修改mysqladmin家目录权限

[[email protected] local]# chown -R mysqladmin:dba /usr/local/mysql
[[email protected] local]# chmod -R 755 /usr/local/mysql
[[email protected] local]# su - mysqladmin

#创建arch目录 存储binlog 归档日志
[[email protected] ~]$ mkdir arch

第七步: scripts/mysql_install_db 重新安装

!!可能会出现缺少libaio.so包的错误。yum -y install libaio 一下就解决

第八步: 设置mysql开机启动

[[email protected] ~]# cd /usr/local/mysql
#将服务文件拷贝到init.d下,并重命名为mysql
[[email protected] mysql]# cp support-files/mysql.server /etc/rc.d/init.d/mysql 
#赋予可执行权限
[[email protected] mysql]# chmod +x /etc/rc.d/init.d/mysql
#删除服务
[[email protected] mysql]# chkconfig --del mysql
#添加服务
[[email protected] mysql]# chkconfig --add mysql
[[email protected] mysql]# chkconfig --level 345 mysql on
[[email protected] mysql]# vi /etc/rc.local
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

su - mysqladmin -c "/etc/init.d/mysql start --federated"

第九步:启动mysql服务

[[email protected] mysql]# su - mysqladmin
[[email protected] ~]$ pwd
/usr/local/mysql
[[email protected] ~]$ rm -rf my.cnf
[[email protected] ~]$ service mysql start
Starting MySQL.                                            [  OK  ]
[[email protected] ~]$ 
[[email protected] ~]$ service mysql status
MySQL running (3625)                                       [  OK  ]

第十步:LOGIN MYSQL

部署完成后mysql自己有一个root用户,空密码。和一个空用户,空密码。

mysql -uroot -p -h127.0.0.1 这种方式安全
mysql -uroot -p123456 -h127.0.0.1 这种方式不安全,history里有记录
mysql -uroot -p 123456 -h 127.0.0.1 -P3306

第十一步:Update password and Purge user

mysql> use mysql
Database changed
mysql> update user set password=password('123456') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> select host,user,password from user;
+----------------+------+-------------------------------------------+
| host           | user | password                                  |
+----------------+------+-------------------------------------------+
| localhost      | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
| hadoop-01 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
| 127.0.0.1      | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
| ::1            | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
| localhost      |      |                                           |
| hadoop-01 |      |                                           |
+----------------+------+-------------------------------------------+
6 rows in set (0.00 sec)

mysql> delete from user where user='';
mysql> select host,user,password from user;
+----------------+------+-------------------------------------------+
| host           | user | password                                  |
+----------------+------+-------------------------------------------+
| localhost      | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
| hadoop-01 | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
| 127.0.0.1      | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
| ::1            | root | *6340BE3C15D246B0D74BAF3F135915ED19E0069F |
+----------------+------+-------------------------------------------+
4 rows in set (0.00 sec)

#针对用户 权限的操作语句 养成习惯 都最后一步执行刷新权限
mysql> flush privileges;

第十二步:配置个人环境变量文件.bash_profile

hadoop-01:mysqladmin:/usr/local/mysql:>cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
	. ~/.bashrc
fi

# User specific environment and startup programs
export MYSQL_HOME=/usr/local/mysql
export PATH=${MYSQL_HOME}/bin:$PATH


export PATH
PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1

在拼接$PATH时,注意要将原PATH拼接在后面