linux mysql环境搭建_mysql在linux环境的搭建部署

本文详述了在Linux系统中搭建MySQL5.6的步骤,包括下载安装包、创建用户组和用户、配置安装、解决安装过程中遇到的错误(如Perl模块缺失和libaio库问题),以及远程访问时的密码设置和权限调整。同时,针对安装后可能遇到的1130错误和云服务器端口限制提供了解决方案。
摘要由CSDN通过智能技术生成

1、下载mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz

d6b55bffd3dd42484de9391b996927a5.png

2、解压到安装目录

#解压

tar -zxvf mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz

#添加目录

mkdir -p /usr/local/mysql

#复制解压后的mysql目录

cp -r mysql-5.6.33-linux-glibc2.5-x86_64 /usr/local/

3、添加用户组和用户

#添加用户组

groupadd mysql

#添加用户mysql 到用户组mysql

useradd -g mysql mysql

4、安装

1)、cd /usr/local/

2)、rename mysql-5.6.30-linux-glibc2.5-x86_64 mysql *

3)、cd /usr/local/mysql/

4)、mkdir -p ./data/mysql

5)、chown -R mysql:mysql ./

6)、./scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/data/mysql (错误1)

7)、cp support-files/mysql.server /etc/init.d/mysqld (错误2)

8)、chmod 755 /etc/init.d/mysqld

9)、cp support-files/my-default.cnf /etc/my.cnf

10)、 #修改启动脚本

vi /etc/init.d/mysqld

11)、#修改项:

basedir=/usr/local/mysql/

datadir=/usr/local/mysql/data/mysql

12)、#启动服务

service mysqld start

13)、#测试连接

./mysql/bin/mysql -uroot

14)、#加入环境变量,编辑 /etc/profile,这样可以在任何地方用mysql命令了

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

说明:

#启动mysql service mysqld start

#关闭mysql service mysqld stop

#查看运行状态  service mysqld status

备注:安装过程遇到错误莫要慌张

错误1、FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:

Data::Dumper

解决方法 :安装autoconf库  命令:yum-y install autoconf

错误2、Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No                            such file or directory

当我们使用“mysql_install_db”安装MySQL时,需要libaio包,现将不同Linux系统安装该包的方式总结如下:

1、对于Redhat/CentOS系统用如下安装方式:[root@dbhost01~]# yum install libaio

2、对Debian系统用如下安装方式:root@dbhost01:~# apt-get install libaio1

91a84b377065d82e1744ff33d0ac5b4c.png

远程访问注意事项:

远程访问时需要密码安装全程没有设置过密码就需要修改密码了

停止msql服务

ps -ef|grep mysql

f2ef44a8d1ac70e4d3fb8d85ed544f1d.png

杀死进程  kill -9 8389

2.修改MySQL的登录设置:

# vi /etc/my.cnf

在[mysqld]的段中加上一句:skip-grant-tables

例如:

[mysqld]

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

skip-grant-tables

保存并且退出vi。

3.重新启动mysqld

# service mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

4.登录并修改MySQL的root密码

# ./mysql/bin/mysql -uroot

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3 to server version: 3.23.56

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> USE mysql ;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;

Query OK, 0 rows affected (0.00 sec)

Rows matched: 2 Changed: 0 Warnings: 0

mysql> flush privileges ;

Query OK, 0 rows affected (0.01 sec)

mysql> quit

Bye

5.将MySQL的登录设置修改回来

# vi /etc/my.cnf

将刚才在[mysqld]的段中加上的skip-grant-tables删除

保存并且退出vi。

6.重新启动mysqld

# service mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

连接时,报1130错误,是由于没有给远程连接的用户权限问题

解决1:更改 ‘mysql’数据库‘user’表‘host’项,从‘localhost’改成‘%’。

use mysql;

select 'host' from user where user='root';

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

flush privileges;

解决2:直接授权

GRANT ALL PRIVILEGES ON *.* TO ‘root’@'%’ IDENTIFIED BY ‘youpassword’ WITH GRANT OPTION;

云服务器端口没开放问题

ba505250cf08e877c3764843bd6d8ac9.png

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值