1:系统版本
[root@vhost1 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.5 (Santiago)
2:添加用户和组
chattr -i /etc/shadow /etc/group /etc/gshadow /etc/passwd
/usr/sbin/groupadd -g 200 mysql
/usr/sbin/useradd mysql -u200 -g mysql -s /sbin/nologin
3:启动文件、my.cnf文件、创建MySQL软件目录
/opt/source #软件解压目录
basedir=/usr/local/mysql #软件安装目录
datadir=/mysqldata #数据目录
解压软件到安装目录下
#tar zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql
在软件目录/opt/source下解压
tar zxvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz mysql
建立软连接,便于日后版本升级
ln -r /opt/source/mysql /usr/local/mysql
chattr +i /etc/shadow /etc/group /etc/gshadow /etc/passwd
chown -R mysql:mysql $basedir $basedir #改权限
创建启动MySQL启动文件
cp -rf $basedir/support-files/mysql.server /etc/init.d/mysql
/sbin/chkconfig --add mysql
/sbin/chkconfig --level 2345 mysql on
创建执行文件的链接文件
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin
ln -s /usr/local/mysql/bin/mysqld /usr/bin/mysqld
ln -s /usr/local/mysql/bin/mysqlshow /usr/bin/mysqlshow
4:编辑my.cnf
cp $basedir/support-files/my.cnf.nor /etc/my.cnf
vi /etc/my.cnf
[mysqld]中添加:
server_id = 1
port = 3306
basedir = /usr/local/mysql datadir = /mysqldata
5:初始化数据字典
>5.6 初始化mysql表、test表、infomation表等
mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/mysqldata
PS:该步骤有可能会报错误 安装需要的包即可:libstdc++.so.6和libaio.so.1和libncurses.so.5
>5.7
mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysqldata
#会生成随机密码。加--initialize初始化时候保持5.5,5.6一致,生成空密码
注意,记住初始化数据库生成登录MySQL数据库的root密码,一会登录数据库要用
6;启动MySQL服务
service mysql start
grep password*.log
set password=password('mysql');
7:登陆MySQL
5.6 删除空用户
select user,host from mysql.user;
mysql> DROP USER ''@localhost;
mysql> UPDATE mysql.user set password = PASSWORD('gechong') WHERE user = 'root';
mysql> FLUSH PRIVILEGES;
5.7
mysql> set password='123456'; (因为刚才使用的密码是个默认的登录密码,所以我们要修改)
mysql> flush privileges;