安装之前
确认是否已安装旧版mysql。如有,则卸载(注意需要的数据备份)。
/etc/init.d/mysqld stop
yum remove mysql mysql-*
rm -rf /var/lib/mysql
rm /etc/my.cnf
下载
下载
wget https://dev.mysql.com/get/downloads/mysql-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
解压
tar xzf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
移动到目录
mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql
配置
创建数据目录,如
mkdir /usr/local/mysql_data
修改/etc/my.cnf,没有则创建,输入以下内容:
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
skip-name-resolve
sql_mode=""
max_connections=10000
datadir=/usr/local/mysql_data
socket=/tmp/mysql.sock
user=mysql
disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
character-set-server=utf8mb4
collation_server=utf8mb4_unicode_ci
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
配置mysql目录用户及权限
groups mysql (检查是否存在mysql组,没有则创建)
groupadd mysql (如不存在)
su mysql (检查是否存在mysql用户,没有则创建)
useradd -r -g mysql mysql (如不存在)
cd /usr/local/mysql/
chown -r mysql:mysql ./
初始化
./bin/mysqld --initialize --user=mysql
注意这里会生成一个临时密码,记住它,第一次登陆时需要
可能遇到的错误:
libaio.so.1: cannot open shared object file
解决:yum install libaio
再次修改mysql目录用户及权限
cd /usr/local/mysql/
chown -r root:root ./
cd /usr/local/mysql_data
chown -r mysql:mysql ./
启动mysqld
cd /usr/local/mysql/
./bin/mysqld &
初次访问
建立软链接,将mysql命令加入可执行检索路径中
ln -s /usr/local/mysql/bin/mysql /bin/mysql
访问mysql
mysql -uroot -p -h localhost
按提示输入初次密码
更改密码
update mysql.user set password=password('your_new_password')
where user='root';
报错后执行:
set password = password('your_new_password');
授权远程登录
grant all privileges on . to root@'%' identified by 'your_new_password';
flush privileges;
退出mysql。
配置mysql服务方便自启动
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
服务命令
service mysqld status
service mysqld start
service mysqld stop
service mysqld restart
如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!