7.linux下安装mysql
-
卸载清除mysql 我的都是新系统 未做相关操作
-
检查是否有安装mysql,两种方法
- rpm -qa | grep mysql (如果你不知道MySQL的安装方式,千万不要用这命令来判别是否安装了MySQL)
- yum list installed | grep mysql
- 有mysql开头的就是有
-
卸载前要关闭mysql服务
- 方法一
- service mysql status
- service mysql stop
- service mysql status
- 方法二
- ./mysql status
- ./mysql stop
- ./mysql status
- chkconfig --list | grep -i mysql 这是要查看是否还有mysql在执行的程序?
- 方法一
-
收集mysql对应文件夹
- find / -name mysql 最好用find查
- whereis mysql 另外一种方式
-
卸载mysql
- rpm -ev MySQL-devel-5.6.23-1.linux_glibc2.5
- rpm -ev MySQL-server-5.6.23-1.linux_glibc2.5
- rpm -ev MySQL-client-5.6.23-1.linux_glibc2.5
-
删除对应文件夹
-
删除mysql用户及用户组
-
-
mysql免安装模式
-
下载tar.gz格式文件,上传到linux设备,能不能用wget直接下载呢?我没试,,,
-
tar -xzvf -mysql-.........tar.gz 解压压缩包
-
mv修改压缩包名 我理解的是为了后边简化一些
-
检查和创建用户及用户组
- cat /etc/group |grep mysql
- cat /etc/passwd | grep mysql
- groupadd mysql
- useradd -rg mysql mysql
-
创建data目录,现在不会自动生成了,要创建。我在usr/local下没法安装 所以放在了opt下 /opt/mysql/data
-
授权目录和用户 这一步目前还不太理解
- cd mysql文件夹上一层目录
- chown -R mysql:mysql mysql/
- chmod -R 755 mysql/
-
删除原有/etc/my.cnf或者备份 find -name my.cnf
-
/opt/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/mysql/data --basedir=/opt/mysql
- 没有error 安装正常 最后的部分是临时密码
- 目前有碰到error 提示shutdown now 重启后正常
-
cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld 复制启动脚本到资源目录
-
创建命令的软连接 ln -s /usr/local/mysql/bin/mysql /usr/bin
- 一般也有映射到/usr/local/bin目录下的
- 在目标目录下 可以直接 ln -fs /原绝对路径/bin/mysql mysql
- mysqldmin mysqldump等不可用时候都可按此方法操作
- 不创建的话 会报 bash:command not found的错误
-
chmod +x /etc/rc.d/init.d/mysqld 增加mysqld服务控制脚本执行权限
-
chkconfig --add mysqld 将mysqld服务加入到系统服务
-
启动前先在/etc下创建my.cnf文件 注意 我这里有问题,注释掉了pid-file和socket这两个项 后边有无问题再说
-
service mysqld start 启动mysqld服务
- 启动失败,各种)()&&……*&,最后的解决办法是,在/etc下创建my.cnf
- 创建的有问题 把pid-file和socket这两项注释掉了
-
剩下的就是和window一样进入数据库,输入之前生成的临时密码
-
做任何操作都提示先修改密码,曰,记得有五六种改密码的方式,都不行,还得按规矩来。
-
alter user 'root'@localhost identified by 'newpassword';
-
之前操作没有设置端口,需要设置端口的时候发现没地方设置,配置/etc/sysconfig/iptables文件
-
安装iptables 没有是因为没安装,需要安装iptables 安装前 centos7默认使用firewall作为防火前,先停掉
-
systemctl stop firewalld
-
systemctl mask firewalld
-
yum install -y iptables
-
yum install iptables-services
-
这个时候有iptables文件了
-
在配置文件里,22端口下边复制黏贴一份 -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-
systemctl start iptables.service
-
systemctl restart iptables.service // 重启防火墙使配置生效
-
systemctl enable iptables.service // 设置防火墙开机启动
-
iptables相关命令
iptables相关命令 点击查看
service iptables status #检查是否安装了iptables yum install -y iptables #安装iptables yum update iptables #升级iptables yum install iptables-services #安装iptables-services systemctl disable iptables #禁止iptables服务 systemctl stop iptables #暂停服务 systemctl enable iptables #解除禁止iptables systemctl start iptables #开启服务
-
-
以上步骤完成后,用sqlyog远程连接不行,需要把对应IP加进来
- GRANT ALL PRIVILEGES ON . TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
-
补充 flush privileges; 出现error 1146 情况
- 进入mysql库 网上资料说能看到servers表 可以看到server.ibd和server.frm 可知是innodb表 我看不到servers表
- 这里网上资料要执行一步 drop table if exists servers;
- show warnings; 查看上一步的错误
- 随后妄图在创建servers表失败
- 正式创建的表如下 设置数据库打开这张表的默认引擎是MyISAM,但是这张表键表的时候引擎是INNODB
点击查看代码
CREATE TABLE 'servers'( 'Server_name' char(64) NOT NULL, 'Host' char(64) NOT NULL, 'Db' char(64) NOT NULL, 'Username' char(64) NOT NULL, 'Password' char(64) NOT NULL, 'Port' int(4) DEFAULT NULL, 'Socket' char(64) DEFAULT NULL, 'Wrapper' char(64) NOT NULL, 'Owner' char(64) NOT NULL, PRIMARY KEY ('Server_name') ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
-