mysql 5.7.18安装教程
下载
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
[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
内容分享