Centos安装配置Mysql,以及防火墙的设置
来源:互联网 发布:广州java开发外包人力 编辑:程序博客网 时间:2024/06/01 08:02
Centos6.5:
yum -yinstallmysqlmysql-servermysql-devel
Centos7:
由于yum中没有mysql的资源,所以先安装带有当前可用的mysql5系列社区版资源的rpm包。
#######安装rpm包[root@typecodes ~]# rpm -Uvh http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpmRetrieving http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpmPreparing... ################################# [100%]Updating / installing... 1:mysql-community-release-el7-5 ################################# [100%]
这时查看当前可用的mysql安装资源:
[root@typecodes ~]# yum repolist enabled | grep "mysql.*-community.*"mysql-connectors-community/x86_64 MySQL Connectors Community 14mysql-tools-community/x86_64 MySQL Tools Community 17mysql56-community/x86_64 MySQL 5.6 Community Server 139
从上面的列表可以看出, mysql56-community/x86_64
和 MySQL 5.6 Community Server
可以使用。
因此,我们就可以直接用yum方式安装了MySQL5.6版本了。
[root@typecodes ~]# yum -y install mysql-community-serverLoaded plugins: axelget, langpacksNo metadata available for baseNo metadata available for epelNo metadata available for extras(Failed to load module fastestmirror: No module named fastestmirror)repomd.xml | 2.5 kB 00:00:00 update mysql-connectors-community metadata successfully(Failed to load module fastestmirror: No module named fastestmirror)repomd.xml | 2.5 kB 00:00:00 update mysql-tools-community metadata successfully(Failed to load module fastestmirror: No module named fastestmirror)repomd.xml | 2.5 kB 00:00:00 update mysql56-community metadata successfullyNo metadata available for updatesmysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql56-community | 2.5 kB 00:00:00 (1/3): mysql-connectors-community/x86_64/primary_db | 7.3 kB 00:00:00 (2/3): mysql56-community/x86_64/primary_db | 83 kB 00:00:01 mysql-tools-community/x86_64/p FAILED ============================================== ] 19 kB/s | 92 kB 00:00:00 ETA http://repo.mysql.com/yum/mysql-tools-community/el/7/x86_64/repodata/3301d2eb425f300dec5a46c4201d08f2cf9232a6-primary.sqlite.bz2: [Errno 12] Timeout on http://repo.mysql.com/yum/mysql-tools-community/el/7/x86_64/repodata/3301d2eb425f300dec5a46c4201d08f2cf9232a6-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 3 seconds')Trying other mirror.(3/3): mysql-tools-community/x86_64/primary_db | 15 kB 00:00:00 Resolving Dependencies--> Running transaction check---> Package mysql-community-server.x86_64 0:5.6.24-3.el7 will be installed--> Processing Dependency: mysql-community-common(x86-64) = 5.6.24-3.el7 for package: mysql-community-server-5.6.24-3.el7.x86_64--> Processing Dependency: mysql-community-client(x86-64) = 5.6.24-3.el7 for package: mysql-community-server-5.6.24-3.el7.x86_64--> Processing Dependency: perl(DBI) for package: mysql-community-server-5.6.24-3.el7.x86_64--> Running transaction check---> Package mariadb.x86_64 1:5.5.41-2.el7_0 will be obsoleted---> Package mysql-community-client.x86_64 0:5.6.24-3.el7 will be obsoleting--> Processing Dependency: mysql-community-libs(x86-64) = 5.6.24-3.el7 for package: mysql-community-client-5.6.24-3.el7.x86_64---> Package mysql-community-common.x86_64 0:5.6.24-3.el7 will be installed---> Package perl-DBI.x86_64 0:1.627-4.el7 will be installed--> Processing Dependency: perl(RPC::PlServer) >= 0.2001 for package: perl-DBI-1.627-4.el7.x86_64--> Processing Dependency: perl(RPC::PlClient) >= 0.2000 for package: perl-DBI-1.627-4.el7.x86_64--> Running transaction check---> Package mariadb-libs.x86_64 1:5.5.41-2.el7_0 will be obsoleted--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.41-2.el7_0 for package: 1:mariadb-devel-5.5.41-2.el7_0.x86_64---> Package mysql-community-libs.x86_64 0:5.6.24-3.el7 will be obsoleting---> Package perl-PlRPC.noarch 0:0.2020-14.el7 will be installed--> Processing Dependency: perl(Net::Daemon) >= 0.13 for package: perl-PlRPC-0.2020-14.el7.noarch--> Processing Dependency: perl(Net::Daemon::Test) for package: perl-PlRPC-0.2020-14.el7.noarch--> Processing Dependency: perl(Net::Daemon::Log) for package: perl-PlRPC-0.2020-14.el7.noarch--> Processing Dependency: perl(Compress::Zlib) for package: perl-PlRPC-0.2020-14.el7.noarch--> Running transaction check---> Package mariadb-devel.x86_64 1:5.5.41-2.el7_0 will be obsoleted---> Package mysql-community-devel.x86_64 0:5.6.24-3.el7 will be obsoleting---> Package perl-IO-Compress.noarch 0:2.061-2.el7 will be installed--> Processing Dependency: perl(Compress::Raw::Zlib) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch--> Processing Dependency: perl(Compress::Raw::Bzip2) >= 2.061 for package: perl-IO-Compress-2.061-2.el7.noarch---> Package perl-Net-Daemon.noarch 0:0.48-5.el7 will be installed--> Running transaction check---> Package perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 will be installed---> Package perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved======================================================================================================================================================================= Package Arch Version Repository Size=======================================================================================================================================================================Installing: mysql-community-client x86_64 5.6.24-3.el7 mysql56-community 19 M replacing mariadb.x86_64 1:5.5.41-2.el7_0 mysql-community-devel x86_64 5.6.24-3.el7 mysql56-community 3.4 M replacing mariadb-devel.x86_64 1:5.5.41-2.el7_0 mysql-community-libs x86_64 5.6.24-3.el7 mysql56-community 2.0 M replacing mariadb-libs.x86_64 1:5.5.41-2.el7_0 mysql-community-server x86_64 5.6.24-3.el7 mysql56-community 58 MInstalling for dependencies: mysql-community-common x86_64 5.6.24-3.el7 mysql56-community 256 k perl-Compress-Raw-Bzip2 x86_64 2.061-3.el7 base 32 k perl-Compress-Raw-Zlib x86_64 1:2.061-4.el7 base 57 k perl-DBI x86_64 1.627-4.el7 base 802 k perl-IO-Compress noarch 2.061-2.el7 base 260 k perl-Net-Daemon noarch 0.48-5.el7 base 51 k perl-PlRPC noarch 0.2020-14.el7 base 36 kTransaction Summary=======================================================================================================================================================================Install 4 Packages (+7 Dependent packages)Total download size: 83 MDownloading packages:mysql-community-devel-5.6.24-3.el7.x86_64.rpm | 3.4 MB 00:00:03 mysql-community-client-5.6.24-3.el7.x86_64.rpm | 19 MB 00:00:05 mysql-community-server-5.6.24-3.el7.x86_64.rpm | 58 MB 00:00:11 mysql-community-libs-5.6.24-3.el7.x86_64.rpm | 2.0 MB 00:00:02 perl-DBI-1.627-4.el7.x86_64.rpm | 0 B 00:00:01 ... perl-DBI-1.627-4.el7.x86_64.rpm | 802 kB 00:00:00 (1/6): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm | 57 kB 00:00:00 (2/6): perl-Net-Daemon-0.48-5.el7.noarch.rpm | 51 kB 00:00:00 (3/6): perl-PlRPC-0.2020-14.el7.noarch.rpm | 36 kB 00:00:00 (4/6): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm | 32 kB 00:00:00 (5/6): perl-IO-Compress-2.061-2.el7.noarch.rpm | 260 kB 00:00:00 warning: /var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.24-3.el7.x86_64.rpm: V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY 00:00:01 ETA Public key for mysql-community-common-5.6.24-3.el7.x86_64.rpm is not installed(6/6): mysql-community-common-5.6.24-3.el7.x86_64.rpm | 256 kB 00:00:01 -----------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 388 kB/s | 692 kB 00:00:01 Retrieving key from file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlImporting GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5 Package : mysql-community-release-el7-5.noarch (installed) From : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysqlRunning transaction checkRunning transaction testTransaction test succeededRunning transactionWarning: RPMDB altered outside of yum. Installing : mysql-community-common-5.6.24-3.el7.x86_64 1/14 Installing : mysql-community-libs-5.6.24-3.el7.x86_64 2/14 Installing : mysql-community-client-5.6.24-3.el7.x86_64 3/14 Installing : perl-Net-Daemon-0.48-5.el7.noarch 4/14 Installing : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 5/14 Installing : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 6/14 Installing : perl-IO-Compress-2.061-2.el7.noarch 7/14 Installing : perl-PlRPC-0.2020-14.el7.noarch 8/14 Installing : perl-DBI-1.627-4.el7.x86_64 9/14 Installing : mysql-community-server-5.6.24-3.el7.x86_64 10/14 Installing : mysql-community-devel-5.6.24-3.el7.x86_64 11/14 Erasing : 1:mariadb-devel-5.5.41-2.el7_0.x86_64 12/14 Erasing : 1:mariadb-5.5.41-2.el7_0.x86_64 13/14 Erasing : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 14/14 Verifying : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64 1/14 Verifying : mysql-community-common-5.6.24-3.el7.x86_64 2/14 Verifying : mysql-community-devel-5.6.24-3.el7.x86_64 3/14 Verifying : mysql-community-client-5.6.24-3.el7.x86_64 4/14 Verifying : perl-PlRPC-0.2020-14.el7.noarch 5/14 Verifying : mysql-community-server-5.6.24-3.el7.x86_64 6/14 Verifying : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64 7/14 Verifying : mysql-community-libs-5.6.24-3.el7.x86_64 8/14 Verifying : perl-Net-Daemon-0.48-5.el7.noarch 9/14 Verifying : perl-DBI-1.627-4.el7.x86_64 10/14 Verifying : perl-IO-Compress-2.061-2.el7.noarch 11/14 Verifying : 1:mariadb-5.5.41-2.el7_0.x86_64 12/14 Verifying : 1:mariadb-devel-5.5.41-2.el7_0.x86_64 13/14 Verifying : 1:mariadb-libs-5.5.41-2.el7_0.x86_64 14/14 Installed: mysql-community-client.x86_64 0:5.6.24-3.el7 mysql-community-devel.x86_64 0:5.6.24-3.el7 mysql-community-libs.x86_64 0:5.6.24-3.el7 mysql-community-server.x86_64 0:5.6.24-3.el7 Dependency Installed: mysql-community-common.x86_64 0:5.6.24-3.el7 perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7 perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7 perl-DBI.x86_64 0:1.627-4.el7 perl-IO-Compress.noarch 0:2.061-2.el7 perl-Net-Daemon.noarch 0:0.48-5.el7 perl-PlRPC.noarch 0:0.2020-14.el7 Replaced: mariadb.x86_64 1:5.5.41-2.el7_0 mariadb-devel.x86_64 1:5.5.41-2.el7_0 mariadb-libs.x86_64 1:5.5.41-2.el7_0 Complete!
安装完MySQL后,需要进行一些基础配置工作:
#######安装成功后,将其加入开机启动[root@typecodes ~]# systemctl enable mysqld#######启动mysql服务进程[root@typecodes ~]# systemctl start mysqld#######配置mysql(设置密码等)[root@typecodes ~]# mysql_secure_installationNOTE: 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 currentpassword for the root user. If you've just installed MySQL, andyou haven't set the root password yet, the password will be blank,so you should just press enter here.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 MySQLroot user without the proper authorisation.Set root password? [Y/n] y [设置root用户密码]New password: Re-enter new password: Password updated successfully!Reloading privilege tables.. ... Success!By default, a MySQL installation has an anonymous user, allowing anyoneto log into MySQL without having to have a user account created forthem. This is intended only for testing, and to make the installationgo a bit smoother. You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y [删除匿名用户] ... Success!Normally, root should only be allowed to connect from 'localhost'. Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n [禁止root远程登录] ... Success!By default, MySQL comes with a database named 'test' that anyone canaccess. This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y [删除test数据库] - Dropping test database...ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y [刷新权限] ... Success!All done! If you've completed all of the above steps, your MySQLinstallation should now be secure.Thanks for using MySQL!Cleaning up...
最后是防火墙的设置
Centos6.5:
#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
然后保存:
#/etc/rc.d/init.d/iptables save
# /etc/init.d/iptables status
-------------------------------------------------------
补充说明:
#关闭防火墙
/etc/init.d/iptables stop
service iptables stop # 停止服务
#查看防火墙信息
/etc/init.d/iptables status
#开放端口:8080
/sbin/iptables -I INPUT -p tcp --dport 8080 -j ACCEPT
#重启防火墙以便改动生效:(或者直接重启系统)
/etc/init.d/iptables restart
#将更改进行保存
/etc/rc.d/init.d/iptables save
另外直接在/etc/sysconfig/iptables中增加一行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT
#永久关闭防火墙
chkconfig –level 35 iptables off #此方法源自网络,未实验,安全考虑拒绝使用此方法
Centos7:
CentOS升级到7之后,发现无法使用iptables控制Linuxs的端口,google之后发现Centos 7使用firewalld代替了原来的iptables。下面记录如何使用firewalld开放Linux端口:
开启端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
命令含义:
--zone #作用域
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload
如:
[caibo@localhost /]$ firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[caibo@localhost /]$ firewall-cmd --reload
systemctl stop firewalld.service #停止
systemctl disable firewalld.service #禁用
mysql安装后还要允许远程连接,其他服务器才能连接到本地的数据库。
mysql账户是否不允许远程连接。如果无法连接可以尝试以下方法:
mysql -u root -p //登录MySQL
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION; //任何远程主机都可以访问数据库
mysql> FLUSH PRIVILEGES; //需要输入次命令使修改生效
mysql> EXIT //退出
也可以通过修改表来实现远程:
mysql -u root -p
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user;
整合至:
http://www.tuicool.com/articles/rUrAv2
http://www.linuxidc.com/Linux/2015-03/114749.htm
http://blog.163.com/bo_cai@yeah/blog/static/86096191201541963521154/
- Centos安装配置Mysql,以及防火墙的设置
- CentOS 7防火墙的设置以及端口的开启
- centos7中ssh开启以及mysql数据库的安装还有防火墙的配置
- centos的安装以及yum源的配置以及视频flash的设置
- CentOS 自带防火墙 Firewalld 的安装与配置
- Centos 7 Nginx安装与防火墙的配置
- 嵌入式 iptables防火墙的配置以及设置nat
- CentOS下防火墙的配置
- 关于CentOS防火墙的配置
- CentOS下防火墙的配置
- centos下安装FTP,设置防火墙
- CentOS 6 Telnet安装与防火墙设置
- CentOS下使用yum安装Mysql,以及Mysql主从复制的配置
- centos下安装openfire以及mySQL配置(默认安装)
- Centos 6.4安装:防火墙+JDK7+tomcat8+mysql
- centos mysql的安装和系统设置
- CentOS下Mysql数据库的安装与配置以及遇到的问题及其解决方案
- CentOS 6.3 安装以及配置Apache php mysql
- 【HUSTOJ】1026: 判断素数
- 13.反转链表
- 时代浪潮
- HDU 1233 还是畅通工程(最小生成树)
- Xcode Build Search Paths设置
- Centos安装配置Mysql,以及防火墙的设置
- HTML5----响应式(自适应)网页设计
- Nodejs学习item 2 -- events事件处理EventEmitter
- android:exported 属性详解
- linux下c++编程环境搭建,运行过程以及调试
- c#调用系统DLL
- wince编程常用控制窗体API
- windows编程常用消息汇总
- 常用键盘键值