A.建立mysql用户、用户组、home目录
groupadd mysql
useradd -G mysql -m /home/mysql -s /bin/bash mysql
b.安装mysql
tar -zxvf mysql-5.5.24-linux2.6-x86_64.tar.gz
mkdir -p /usr/local/mysql
mv ./mysql-5.5.24-linux2.6-x86_64/* /usr/local/mysql/
cd /usr/local/
chown mysql:mysql mysql
C.建立data/log相关目录
mkdir -p /data/mysql/3306/data --datadir
mkdir -p /data/mysql/3306/innodb/data
mkdir -p /data/mysql/3306/innodb/log
mkdir -p /data/mysql/3306/logs/binlogs --log-bin
D.更改data/log目录所有者
chown -R mysql:mysql /data/mysql*
4.初始化默认数据库
A.将/usr/local/mysql/scripts/mysql_install_db移到/usr/local/mysql/bin/mysql_install_db
mv /usr/local/mysql/scripts/mysql_install_db /usr/local/mysql/bin/mysql_install_db
根据应用规模选择配置文件
cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf 修改my.cnf为对应目录。
/usr/local/mysql/bin/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/3306/data --user=mysql
查看/data/mysql/3306/data下会有mysql和test两个数据库。
5.启动mysql
su - mysql
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql &
6.修改密码7zklg@86zKJ
/usr/local/mysql/bin/mysqladmin -u root password '123456'
/usr/local/mysql/bin/mysqladmin -u root -h 127.0.0.1
127.0.0.1
127.0.0.1 password 'new-password
如果已设置过密码,修改使用
mysqladmin -u root password oldpass "newpass"
8.mysql停止
# mysqladmin -u root -p123456 shutdown
其中用户是root,密码是123456