mysql安装
linux安装mysql5.7.24
1、检查是否已安装过mariadb,若有便删除(linux系统自带的)
rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
2、检查是否已安装过mysql,若有便删除(linux系统自带的)
rpm -qa | grep mysql
rpm -e –-nodeps mysql-libs-5.1.52.x86_64
3、检查mysql组和用户是否存在,如无创建:
cat /etc/group | grep mysql
cat /etc/passwd |grep mysql
groupadd mysql
useradd -r -g mysql mysql
4、从官网下载mysql安装包,解压后移动到/usr/local/mysql下(自己自定义安装的目录)
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
可用其他下载方式
tar xzvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.24-linux-glibc2.12-x86_64 /usr/local/mysql
5、在mysql下添加data目录
mkdir /usr/local/mysql/data
6、更改mysql目录下所有的目录及文件夹所属组合用户
cd /usr/local/
chown -R mysql:mysql mysql/
chmod -R 755 mysql/
7、编译安装并初始化mysql,记住命令行末尾的密码:
/usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql
以下是执行所示begin
2019-07-26T04:51:20.568409Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-07-26T04:51:20.830534Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-07-26T04:51:20.887254Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-07-26T04:51:20.954176Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 030f6be4-af61-11e9-b5de-fefcfeec7a93.
2019-07-26T04:51:20.957872Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-07-26T04:51:20.958661Z 1 [Note] A temporary password is generated for root@localhost: 8QFZTNdqv?/#
以下是执行所示end
8QFZTNdqv?/# ----- 》即是随机密码
8、启动mysql服务
/usr/local/mysql/support-files/mysql.server start
(若出现)--------
/data/mysql/support-files/mysql.server: line 239: my_print_defaults: command not found
/data/mysql/support-files/mysql.server: line 259: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
vi /usr/local/mysql/support-files/mysql.server
将上面初始化的--datadir=/usr/local/mysql/data --basedir=/usr/local/mysql路径写入到mysql.server里面对应的配置
再次重启
9、做个软连接,重启服务
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
10、做个软链接,将安装目录下的mysql 放在/usr/bin 目录下
ln -s /usr/local/mysql/bin/mysql /usr/bin
11、登录msyql,输入密码(密码为步骤7初始化生成的密码)
mysql -u root -p
Enter password:
12、修改密码并开放远程
msql>alter user 'root'@'localhost' identified by '123456';
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
mysql>quit
13、编辑my.cnf,添加配置文件,配置内容为
vi /usr/local/mysql/my.cnf
[mysqld]
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#skip-grant-tables#忽略权限直接登录
14、设置开机自启动
1、将服务文件拷贝到init.d下,并重命名为mysql
[root@localhost local]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、赋予可执行权限
[root@localhost local]# chmod +x /etc/init.d/mysqld
3、添加服务
[root@localhost local]# chkconfig --add mysqld
4、显示服务列表
[root@localhost local]# chkconfig --list
5、重启服务器
[root@localhost local]# reboot
若遇到远程仍无法连接请检查防火墙或网络
一、iptables防火墙
1、基本操作
# 查看防火墙状态
service iptables status
# 停止防火墙
service iptables stop
# 启动防火墙
service iptables start
# 重启防火墙
service iptables restart
# 永久关闭防火墙
chkconfig iptables off
# 永久关闭后重启
chkconfig iptables on
2、开启80端口
vim /etc/sysconfig/iptables
# 加入如下代码
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
保存退出后重启防火墙
service iptables restart
二、firewall防火墙
1、查看firewall服务状态
systemctl status firewalld
出现Active: active (running)切高亮显示则表示是启动状态。
出现 Active: inactive (dead)灰色表示停止,看单词也行。
2、查看firewall的状态
firewall-cmd --state
3、开启、重启、关闭、firewalld.service服务
# 开启
service firewalld start
# 重启
service firewalld restart
# 关闭
service firewalld stop
4、查看防火墙规则
firewall-cmd --list-all
5、查询、开放、关闭端口
# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 开放80端口
firewall-cmd --permanent --add-port=80/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp
#重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload
# 参数解释
1、firwall-cmd:是Linux提供的操作firewall的一个工具;
2、--permanent:表示设置为持久;
3、--add-port:标识添加的端口;
主备
https://www.cnblogs.com/ahaii/p/6307648.html