官网链接:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
tar zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz -C /usr/local/mysql
建议:不要安装到其它目录,否则数据库初始化的时候会报cannot change dir的错,不好搞
mv mysql-5.7.22-linux-glibc2.12-x86_64 mysql
查看:rpm -qa | grep mysql
卸载:rpm -e --nodeps softfullname
创建用户组:groupadd mysql
创建用户:useradd -r -g mysql mysql
为了安全性,给mysql数据库创建专有用户,该用户只能访问mysql目录,不能访问系统其它目录
另外不建议直接用root初始化mysql,否则连接mysql时会报错:[ERROR] Fatal error: Please read "Security" section of the manual to find out how to run mysqld as root!
首先创建data目录:
cd /usr/local/mysql
mkdir data
指定用户和用户组:
cd /usr/local
chown -R mysql mysql/
chgrp -R mysql mysql/
-R包含目录下所有和目录和文件
cd /usr/local/mysql/bin
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/ --lc_messages_dir=/usr/local/mysql/share --lc_messages=en_US
记住生成的临时密码
如果忘记密码或者想重新初始化,可以先将mysql/data目录中文件删除,然后再执行初始化命令
从5.7.17后mysql就没有默认的my_default.cnf文件,需要手动创建
cd /etc
cat>>my.cnf
输入以下内容,ctrl+D退出
精简版:
[mysqld]
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
lower_case_table_names=1
cd /usr/local/mysql/bin
启动:./mysqld_safe --user=mysql &
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysql
vi /etc/init.d/mysql
将mysql目录填上:
basedir=/usr/local/mysql/
datadir=/usr/local/mysql/data/
授权:chmod +x /etc/init.d/mysql
设为开机启动:chkconfig --add mysql
重启服务:service mysql restart
停止服务:service mysql stop
启动服务:service mysql start
查看服务:service mysql status
cd /usr/local/mysql/bin
登录:./mysql -u root -p 输入临时密码
如果报错: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory
解决:#yum -y install libncurses*
修改密码:set password=password("root");
登录授权:grant all privileges on *.* to'root' @'%' identified by 'root';
授权生效:flush privileges;
修改/etc/my.cnf,在[mysqld]后边添加lower_case_table_names=1 重启mysql服务,这时已设置成功