Centos系统安装MySQL(整理)

5 篇文章 0 订阅

流程参考地址:https://blog.csdn.net/windylfm/article/details/78600977

下载:

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz

网易镜像地址:http://mirrors.163.com/

解压到/usr/local/mysql:

tar -xf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ 
mv /usr/local/mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql

创建mysql的数据库目录,并进行其他相关操作,如下:

mkdir -p /usr/local/mysql/data 
chown -R mysql:mysql /usr/local/mysql/

创建mysql5.6的启动脚本,并进行相关配置,如下:

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld 
vim /etc/init.d/mysqld 
basedir=/usr/local/mysql 
datadir=/usr/local/mysql/data 
chmod +x /etc/init.d/mysqld

初始化mysql5.6,使用如下命令:

cd /usr/local/mysql/scripts/ 
./mysql_install_db –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data

--初始化MySQL问题
1.FATAL ERROR: please install the following Perl modules before executing ./mysql_install_db:
Data::Dumper

需要安装autoconf库
参考地址:http://blog.sina.com.cn/s/blog_694864e60102vaij.html


2.FATAL ERROR: Could not find ./bin/my_print_defaults

认真查看报错信息,可注意到那个路径是相对路径,是以mysql的安装目录为起始。

而初始化则是进去初始化脚本目录里运行脚本,而在这个目录下不会有./bin/my_print_defaults的。

所以回到安装目录以相对路径去执行初始化脚本。

脚本执行路径开始目录 ./scripts/mysql_install_db --user=mysql 。。。。

参考地址:https://blog.csdn.net/m0_37975886/article/details/78329341?locationNum=7&fps=1

3.error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

yum install -y libaio  安装libaio

参考地址:https://blog.csdn.net/eagle89/article/details/78411184

 

创建mysql5.6的my.cnf文件,如下:

cd /usr/local/mysql/support-files 
cp my-default.cnf /etc/my.cnf

把mysql5.6加入到系统环境变量,使用如下命令:

vim /etc/profile 
export PATH=$PATH:/usr/local/mysql/bin 
source /etc/profile 
env

启动mysql5.6,使用如下命令:

/etc/init.d/mysqld start 
netstat -tunlp |grep 3306

我们可以很明显的看出mysql5.6已经安装成功。

--启动MySQL问题

Starting MySQL.. ERROR! The server quit without updating PID file (/usr/loca/mysql/data/mysql.pid ended

重新配置vi /etc/my.cnf 加入 配置的datadir的参数以及其他参数值
参考地址:http://blog.51cto.com/rabbit2013/1341055

给mysql的root用户配置登录密码,使用如下命令:

/usr/local/mysql/bin/mysqladmin -u root password ‘123456’ 
mysql -h127.0.0.1 -uroot -p123456

--赋值root账号问题
Using a password on the command line interface can be insecure
my.cnf中增加skip-grant-tables  去掉验证权限

之后mysql -uroot -p  #直接按回车,这时不需要输入root密码。

然后执行以下语句进行更新root的密码

2

3

update mysql.user set password=password('123456') where User="root" and Host="localhost";

flush privileges; 

grant all on *.* to 'root'@'localhost' identified by '123456' with grant option;

参考地址:https://blog.csdn.net/Penge_/article/details/78184287

--远程连接MySQL不成功,以及root账号不允许远程访问问题

1.防火墙
3306 tcp端口,centos7以后防火墙都采用Firewall了,所以需要firewall命令增加端口号准入
[centos@gps-3 etc]$ sudo firewall-cmd --permanent --add-port=3306/tcp
[centos@gps-3 etc]$ sudo firewall-cmd --reload

firewall的命令参考:https://www.cnblogs.com/moxiaoan/p/5683743.html

2.Host '10.26.2.136' is not allowed to connect to this MySQL server

root账号不允许远程服务器访问的问题

update user set host='%' where user='root';

执行sql会提示下面错误。不理会,直接flush privileges;远程服务器重新远程连接OK。

ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY' 不予理会

参考地址:https://blog.csdn.net/zhangchao19890805/article/details/52628925

3.[centos@gps-3 ~]$ mysql -h10.144.130.183 -ucanal -pcanal
Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'canal'@'gps-3.novalocal' (using password: YES)

当安装MySQL的服务器使用-u -p连接自己时提示验证失败(-u可以直接连接)。但是其他服务可以-u -p远程连接。

select * from mysql.user ;

这是mysql.user表中配置的数据项验证的原因。

root账号删除Host为localhost但password项无值的数据项,便解决了上述问题。

mysql> DELETE FROM `mysql`.`user` WHERE `Host`='127.0.0.1' and`User`='root';
Query OK, 1 row affected (0.00 sec)

mysql> DELETE FROM `mysql`.`user` WHERE `Host`='::1' and`User`='root';
Query OK, 1 row affected (0.01 sec)

mysql> DELETE FROM `mysql`.`user` WHERE `Host`='gps-3.novalocal' and`User`='root';
Query OK, 1 row affected (0.01 sec)

mysql> DELETE FROM `mysql`.`user` WHERE `Host`='gps-3.novalocal' and`User`='';
Query OK, 1 row affected (0.01 sec)

mysql> DELETE FROM `mysql`.`user` WHERE `Host`='localhost' and`User`='';
Query OK, 1 row affected (0.03 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> commit;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值