我这边下的是 mysql-5.7.27-linux-glibc2.12-x86_64.tar.gz
# 解压
tar -zxvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
# 移动
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/
# 重命名
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /usr/local/mysql/data
# mysql用户组
groupadd mysql
# mysql用户
useradd mysql -g mysql
chown -R mysql.mysql /usr/local/mysql
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
# 如果出现以下错误:
2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --
-- server log end --
# 则使用以下命令:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 如果出现以下错误:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 则执行以下命令:
yum -y install numactl
# 如果出现以下错误:
root@bigdata-159:/usr/local/mysql# ./bin/mysqld -- defaults-file=/etc/my.cnf --initialize --user=mysql
./bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
解决方法:
[[email protected] data]# yum install -y libaio //安装后在初始化就OK了
# 完成后继续安装:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 编辑/etc/my.cnf
进入到mysql目录,执行添加MySQL配置的操作
cp support-files/my-medium.cnf /etc/my.cnf
或:
cp support-files/my-default.cnf /etc/my.cnf
是否覆盖?按y 回车
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# 将mysql加入服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# 开机自启
chkconfig mysql on
# 开启
service mysql start
# 登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)
/usr/local/mysql/bin/mysql -u root -p
# 操作mysql数据库
>>use mysql;
# 修改密码
>>update user set authentication_string=password('你的密码') where user='root';
>>flush privileges;
>>exit;
/usr/local/mysql/bin/mysql -u root -p
>>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';
>>exit;
这样就可以通过三方的可视化工具连接操作数据库了。
/usr/local/mysql/bin/mysql -u root -p
>>use mysql;
>>update user set host='%' where user = 'root';
>>flush privileges;
>>eixt;
5、查询、开放、关闭端口
复制代码
# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 开放3306端口
firewall-cmd --permanent --add-port=3306/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
# 参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口;