Linux安装Mysql5.7.28教程
1、官网下载
2、解压tar.xz文件:
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
3、重命名
mv mysql-5.7.28-linux-glibc2.12-x86_64 /usr/local/mysql/mysql-5.7.28
4、添加系统mysql组和mysql用户
groupadd mysql
useradd -r -g mysql mysql
5、创建mysql数据仓库目录:
cd /usr/local/mysql
mkdir /usr/local/mysql/mysql-5.7.28/data
6、修改解压后的mysql目录权限
chown -R mysql:mysql /usr/local/mysql
7、修改mysql的数据库数据默认位置vi /etc/my.cnf,修改后内容如下(注意修改datadir跟socket的值)
[mysqld]
# 设置mysql数据库的数据的存放目录
datadir=/usr/local/mysql/mysql-5.7.28/data
# 设置mysql的安装目录
basedir=/usr/local/mysql/mysql-5.7.28
socket=/usr/local/mysql/mysql-5.7.28/data/mysql.sock
user=mysql
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M
# 允许最大连接数
max_connections=200
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/usr/local/mysql/mysql-5.7.28/data/mariadb.log
pid-file=/usr/local/mysql/mysql-5.7.28/data/mariadb.pid
[client]
port = 3306
socket=/usr/local/mysql/mysql-5.7.28/data/mysql.sock
#
# include all files from the config directory
#
!includedir /etc/my.cnf.d
8、初始化数据库
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/mysql-5.7.28 --datadir=/usr/local/mysql/mysql-5.7.28/data
以上这步骤执行完成后会生成临时密码
A temporary password is generated for root@localhost: r#su##&WF0Xy
9、添加启动服务
cp /usr/local/mysql/mysql-5.7.28/support-files/mysql.server /etc/init.d/mysql
10、启动服务
service mysql start
11、修改root密码
./mysql -uroot -p'r#su##&WF0Xy'
set password for root @localhost = password('root');
12、设置允许远程连接
# 使用数据库mysql
use mysql;
# 设置权限组
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; (password为数据库密码)
# 新增权限生效
flush privileges;
# 查看用户权限组看是否成功:
select User,authentication_string,Host from user;
# 防火墙开放3306端口(根目录下执行)
# 查看服务器开放端口
firewall-cmd --list-ports
# 添加开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
# 重启防火墙
firewall-cmd --reload
13、设置开机自启
添加为服务:
chkconfig --add mysql
查看服务列表:
chkconfig --list
看到3、4、5状态为开或者为 on 则表示成功。如果是 关或者 off 则执行一下:
chkconfig --level 345 mysql on
安装过程中的异常:
- error while loading shared libraries: libnuma.so.1: cannot open shared object file
原因:yum 安装的libnuma.so.1,但安装时默认安装的是32的,但db2需要的是64位的
解决办法:
1.如果已经安装了libnuma.so.1,先yum remove libnuma.so.1
2.yum -y install numactl.x86_64
- Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)
原因是:my.cnf配置文件中设置了[mysqld]的参数socket,而没有设置[client]的参数socket
my.cnf配置文件内容添加
[client]
port=3306
socket=/usr/local/mysql/mysql-5.7.28/data/mysql.sock
- error while loading shared libraries: libncurses.so.5
yum install libncurses*