在这篇文章中,我们将带领您了解【Server】Centos上安装MySQL配置远程访问的全貌,同时,我们还将为您介绍有关CentOS用Yum安装MySql并配置远程登录、centeros配置mysql
在这篇文章中,我们将带领您了解【Server】Centos上安装MySQL配置远程访问的全貌,同时,我们还将为您介绍有关Cent OS 用Yum安装MySql并配置远程登录、centeros 配置 mysql 支持远程访问、CentOS 7中如何安装mysql server、CentOS 7中如何安装mysql server_MySQL的知识,以帮助您更好地理解这个主题。
本文目录一览:- 【Server】Centos上安装MySQL配置远程访问
- Cent OS 用Yum安装MySql并配置远程登录
- centeros 配置 mysql 支持远程访问
- CentOS 7中如何安装mysql server
- CentOS 7中如何安装mysql server_MySQL
【Server】Centos上安装MySQL配置远程访问
安装
- 下载MysqL的repo源
$ wget http://repo.MysqL.com/MysqL-community-release-el7-5.noarch.rpm
- 安装MysqL-community-release-el7-5.noarch.rpm包
$ sudo rpm -ivh MysqL-community-release-el7-5.noarch.rpm
- 安装MysqL
$ sudo yum install MysqL-server
- 重置MysqL密码
$ MysqL -u root
- 重启MysqL服务
$ service MysqLd restart
配置访问权限
- 开放3306入口权限
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
- 查看端口设置是否通过
iptables -L -n
state New tcp dpt:3306 说明设置成功
若还未能成功远程访问到数据库进行下一步
- 进入数据库 use MysqL数据库
MysqL> use MysqL;
//下面我们另外添加一个新的 root 用户,密码为空,只允许 192.168.1.100 连接
MysqL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.100' IDENTIFIED BY '' WITH GRANT OPTION;
//@'192.168.1.100'可以替换为@‘%’就可任意ip访问,当然我们也可以直接用 UPDATE 更新 root 用户 Host,但不推荐
MysqL> UPDATE user SET Host='192.168.1.100' WHERE User='root' AND Host='localhost' LIMIT 1;
MysqL> flush privileges;
最后使用Navicat就可以远程访问数据库了
Cent OS 用Yum安装MySql并配置远程登录
- 准备工作
yum 命令:用于添加/删除/更新RPM包,自动解决包的依赖问题以及系统更新升级
yum --help # 只是部分 查看全部请自己动手
-y # 自动应答yes
update[RPM包] # 更新包
list # 可安装和可更新的RPM包
来源: <http://linux.51yip.com/search/yum>
检查软甲是否安装,如果已存在卸载该软件
rpm -qa|grep mysql # 检查软件是否安装
卸载
rpm -e mysql # 普通删除模式
rpm -e --nodeps mysql # 强力删除模式,如果使用上面命令删除时,提示有依赖的其它文件,则用该命令可以对其进行强力删除
查看yum上提供的mysql数据库可下载的版本:
yum list|grep mysql # 得到yum服务器上mysql数据库的可下载版本信息
- 开始安装
yum install -y mysql-server mysql mysql-deve
[root@localhost ~]# yum install mysql-server mysql mysql-deve
# 这里加载fastestmirror插件 用于测试选择最快的yum源
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* addons: mirrors.163.com
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
Setting up Install Process
No package mysql-deve available.
# 检查并解决rpm包的依赖性
Resolving Dependencies
--> Running transaction check
---> Package mysql.i386 0:5.0.95-5.el5_9 set to be updated
--> Processing Dependency: perl(DBI) for package: mysql
---> Package mysql.x86_64 0:5.0.95-5.el5_9 set to be updated
---> Package mysql-server.x86_64 0:5.0.95-5.el5_9 set to be updated
--> Processing Dependency: perl-DBD-MySQL for package: mysql-server
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:3.0007-2.el5 set to be updated
---> Package perl-DBI.x86_64 0:1.52-2.el5 set to be updated
--> Finished Dependency Resolution
# 汇总依赖性解决结果
Dependencies Resolved
================================================================================
Package Arch Version Repository
================================================================================
Installing:
mysql i386 5.0.95-5.el5_9 base 4
mysql x86_64 5.0.95-5.el5_9 base 4
mysql-server x86_64 5.0.95-5.el5_9 base 9
Installing for dependencies:
perl-DBD-MySQL x86_64 3.0007-2.el5 base 1
perl-DBI x86_64 1.52-2.el5 base 6
Transaction Summary
================================================================================
Install 5 Package(s)
Upgrade 0 Package(s)
Total download size: 20 M
Is this ok [y/N]:
键入y继续
Downloading Packages:
(1/5): perl-DBD-MySQL-3.0007-2.el5.x86_64.rpm | 148 kB 00:00
(2/5): perl-DBI-1.52-2.el5.x86_64.rpm | 600 kB 00:00
(3/5): mysql-5.0.95-5.el5_9.i386.rpm | 4.9 MB 00:02
(4/5): mysql-5.0.95-5.el5_9.x86_64.rpm | 4.9 MB 00:02
(5/5): mysql-server-5.0.95-5.el5_9.x86_64.rpm | 9.9 MB 00:12
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 982 kB/s | 20 MB 00:21
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
base/gpgkey | 1.5 kB 00:00
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <centos-5-key@centos.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
# 这里报了个警告 我Google了一下 没看懂,只好求助度娘
# 原因是:yum安装了旧版本的GPG keys造成的
# 解决方案:rpm --import /etc/pki/rpm-gpg/RPM*
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : perl-DBI 1/5
Installing : mysql 2/5
Installing : perl-DBD-MySQL 3/5
Installing : mysql 4/5
Installing : mysql-server 5/5
Installed:
mysql.i386 0:5.0.95-5.el5_9
mysql.x86_64 0:5.0.95-5.el5_9
mysql-server.x86_64 0:5.0.95-5.el5_9
Dependency Installed:
perl-DBD-MySQL.x86_64 0:3.0007-2.el5
perl-DBI.x86_64 0:1.52-2.el5
Complete!
- 后续配置之MySql安装配置
rpm -qi mysql-server # 查看安装好的mysql-server的版本
[root@localhost ~]# service mysqld start
# 初始化mysql数据库
Initializing MySQL database: Installing MySQL system tables...
OK
Filling help tables...
OK
# 在启动的时候开启mysql服务的提示
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
# 在这里有设置root密码的提示
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password ''new-password''
/usr/bin/mysqladmin -u root -h localhost.localdomain password ''new-password''
# 这是mysql提供的方便我们配置的脚本
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
Starting mysqld: [ OK ]
设置开机启动
chkconfig --list|grep mysqld # 检查mysqld开机启动状态
chkconfig mysqld on # 设置开机启动
chkconfig --list|grep mysqld # 检查mysqld开机启动状态 again
cat /usr/bin/mysql_secure_installation # mysql提供的脚本
[root@localhost ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we''ll need the current
password for the root user. If you''ve just installed MySQL, and
you haven''t set the root password yet, the password will be blank,
so you should just press enter here.
# 这里输入本机的linux密码,如果你现在是root身份登录直接回车即可,我第一次安装的时候 傻傻的输了半天
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
# 设置mysql的root密码 (输入两遍的)
Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
# 是否删除匿名用户
Remove anonymous users? [Y/n] n
... skipping.
Normally, root should only be allowed to connect from ''localhost''. This
ensures that someone cannot guess at the root password from the network.
# 是否限制远程登录
Disallow root login remotely? [Y/n] n
... skipping.
By default, MySQL comes with a database named ''test'' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
# 是否删除测试数据库
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# 重新加载特权表
Reload privilege tables now? [Y/n] Y
... Success!
Cleaning up...
All done! If you''ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@localhost ~]# service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
mysql --help # 信息量太大了 自己看看吧 我英语不及格就不献丑了
-u, --user=name User for login if not current user.
-P, --port=# Port number to use for connection or 0 for default to, in
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/services, built-in default (3306).
mysql -u root -p # 从默认的端口root用户访问数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
+--------------------+
2 rows in set (0.01 sec)
mysql> create database pengfei
-> ; # 创建测试库 大家千万别忘记" ; "
Query OK, 1 row affected (0.00 sec)
mysql> quit
Bye # 太友好了
[root@localhost mysql]# cd /var/lib/mysql # 数据库文件存放目录
[root@localhost mysql]# ls
ibdata1 ib_logfile0 ib_logfile1 mysql mysql.sock pengfei
[root@localhost mysql]# cd pengfei/
[root@localhost pengfei]# ls
db.opt # 数据库文件
- 后续配置之MySql远程访问
mysql配置
mysql -u root -p # 登录
use mysql; # 选择数据库
select host, user from user; # 查询用户表
update user set host = ''%'' where user = ''root''; # 修改主机
# 报了个错 ERROR 1062 (23000): Duplicate entry ''%-root'' for key 1
select host , user from user; # 不过又查询了一下 发现确实改过一个
GRANT ALL PRIVILEGES ON *.* TO ''root''@''%'' IDENTIFIED BY ''your password'' WITH GRANT OPTION; # 授权
FLUSH PRIVILEGES; # 刷新MySQL的系统权限相关表,否则会出现拒绝访问 重启mysql也可以的
cd /etc/init.d # 切换到iptables所在目录
iptables -I INPUT 2 -p tcp -m tcp --dport 3306 -j ACCEPT # MySql
iptables -I INPUT 2 -p tcp -m tcp --dport 1521 -j ACCEPT # Oracle
./iptables save # 保存规则
./iptables restart # 重启防火墙
./iptables states # 查看规则
iptables 参数解释:
–I 参数就看成是插入一条规则
–p 指定是什么协议,我们常用的tcp 协议,当然也有udp,例如53端口的DNS
–dport 就是目标端口,当数据从外部进入服务器为目标端口
–sport 数据从服务器出去,则为数据源端口使用
–j 就是指定是 ACCEPT -接收 或者 DROP 不接收
本文参考:
http://wpguru.co.uk/2012/04/how-to-install-mysql-on-centos-2/
http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html
http://linux.51yip.com/
不积跬步,无以至千里;不积小流,无以成江海。
centeros 配置 mysql 支持远程访问
一、允许 root 用户在任何地方进行远程登录,并具有所有库任何操作权限,具体操作如下:
在本机先使用 root 用户登录 mysql:
mysql -u root -p"youpassword"
进行授权操作:
mysql>GRANT ALL PRIVILEGES ON *.* TO ''root''@''%'' IDENTIFIED BY ''youpassword'' WITH GRANT OPTION;
重载授权表:
FLUSH PRIVILEGES;
退出 mysql 数据库:
exit
二、由于 centeros 防火墙 未设置允许网络访问的时候是拒绝访问的。
所以要设置开放端口访问
允许 3306 端
iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
# 查看规则是否生效
iptables -L -n # 或者: service iptables status
# 此时生产环境是不安全的,远程管理之后应该关闭端口,删除之前添加的规则
iptables -D INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
上面 iptables 添加 / 删除规则都是临时的,如果需要重启后也生效,需要保存修改:
service iptables save # 或者: /etc/init.d/iptables save
另外,
vi /etc/sysconfig/iptables # 加上下面这行规则也是可以的
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
CentOS 7中如何安装mysql server
以前一直用RHEL 6.3和6.4,系统盘里自带了MysqL server,配置好yum源后,直接yum install MysqL-server就可安装MysqL服务器端了,最近用CentOS 7.1,发现系统盘没有提供MysqL-server的RPM包,在网上搜罗了半天,最后在MysqL的官方网站找到答案。
只需在/etc/yum.repos.d/目录下添加以下文件MysqL-community.repo文件,内容如下:
# Enable to use MysqL 5.6 [MysqL56-community] name=MysqL Community Server baseurl=http://repo.MysqL.com/yum/mysql-5.6-community/el/5/$basearch/ enabled=1 gpgcheck= gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL
以上对应的是5.6版本。
5.7版本的内容如下:
# Note: MysqL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https:dev.MysqL.com/doc/relnotes/MysqL/5.7/en/ [MysqL57-community-dmr] name=MysqL 5.7 Community Server Development Milestone Release baseurl=http:repo.MysqL.com/yum/MysqL-5.7-community/el/6/$basearch/ enabled=etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL
最后执行yum install MysqL-community-server即可。
我用的是5.6版本的内容,在安装的过程中,报以下错误:
GPG key retrieval Failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-MysqL"
很显然,本地没有RPM-GPG-KEY-MysqL文件,于是对上文的MysqL-community.repo做了一下修改,修改后的内容如下:
[MysqL56-0
重新执行yum install MysqL-community-server命令,安装OK~
CentOS 7中如何安装mysql server_MySQL
以前一直用RHEL 6.3和6.4,系统盘里自带了mysql server,配置好yum源后,直接yum install mysql-server就可安装mysql服务器端了,最近用CentOS 7.1,发现系统盘没有提供mysql-server的RPM包,在网上搜罗了半天,最后在mysql的官方网站找到答案。
只需在/etc/yum.repos.d/目录下添加以下文件mysql-community.repo文件,内容如下:
# Enable to use MySQL 5.6 [mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
以上对应的是5.6版本。
5.7版本的内容如下:
# Note: MySQL 5.7 is currently in development. For use at your own risk. # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/ [mysql57-community-dmr] name=MySQL 5.7 Community Server Development Milestone Release baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
最后执行yum install mysql-community-server即可。
我用的是5.6版本的内容,在安装的过程中,报以下错误:
GPG key retrieval failed: [Errno 14] curl#37 - "Couldn''t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql"
很显然,本地没有RPM-GPG-KEY-mysql文件,于是对上文的mysql-community.repo做了一下修改,修改后的内容如下:
[mysql56-community] name=MySQL 5.6 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/ enabled=1 gpgcheck=0
重新执行yum install mysql-community-server命令,安装OK~
我们今天的关于【Server】Centos上安装MySQL配置远程访问的分享已经告一段落,感谢您的关注,如果您想了解更多关于Cent OS 用Yum安装MySql并配置远程登录、centeros 配置 mysql 支持远程访问、CentOS 7中如何安装mysql server、CentOS 7中如何安装mysql server_MySQL的相关信息,请在本站查询。
本文标签: