linux安装mysql
安装系统所需要的依赖包
[root@namenode ~]# yum -y install gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* cmake bison
创建mysql用户与用户组
[root@namenode ~]# groupadd mysql
[root@namenode ~]# useradd -r -g mysql mysql
安装mysql
[root@namenode ~]# tar zxvf mysql-5.5.25.tar.gz
[root@namenode ~]# cd mysql-5.5.25
[root@namenode mysql-5.5.25]# cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql/ -DMYSQL_DATADIR=/opt/mysql/data -DMYSQL_UNIX_ADDR=/opt/mysql/data/mysqld.sock -DWITH_INNOBASE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_TCP_PORT=3306 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_UNIX_ADDR=/opt/mysql/data/mysql.sock -DMYSQL_USER=mysql -DWITH_DEBUG=0
[root@namenode mysql-5.5.25]# make && make install
赋予相关权限
[root@namenode mysql-5.5.25]# chown -R mysql:mysql /opt/mysql
[root@namenode mysql-5.5.25]# /opt/mysql/scripts/mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data
mysql配置文件
[root@namenode mysql-5.5.25]# cp /opt/mysql/support-files/my-default.cnf /etc/my.cnf -----有的是
这个文件路径--- cp /opt/mysql/support-files/my-large.cnf /etc/my.cnf 可是没有找打这个文件
[root@namenode mysql-5.5.25]# cp /opt/mysql/support-files/mysql.server /etc/init.d/mysql
[root@namenode mysql-5.5.25]# chmod +x /etc/init.d/mysql
增加自动启动
[root@namenode mysql-5.5.25]# chkconfig mysql on
启动mysql
[root@namenode mysql-5.5.25]# /etc/init.d/mysql start
Starting MySQL...... [ OK ]
查看mysql 的3306端口,看到下面说明启动成功
[root@namenode mysql-5.5.25]#ps aux | grep 3306
mysql 17237 3.6 8.4 615660 86264 pts/2 Sl 22:10 0:01 /opt/mysql/bin/mysqld --basedir=/opt/mysql --datadir=/opt/mysql/data --plugin-dir=/opt/mysql/lib/plugin --user=mysql --log-error=/opt/mysql/data/namenode.err --pid-file=/opt/mysql/data/namenode.pid --socket=/opt/mysql/data/mysql.sock --port=3306
root 17798 0.0 0.0 61228 784 pts/2 S+ 22:10 0:00 grep 3306
设置mysql初始密码,123456是密码,你可以设置自己需要的密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.25-log Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
二、配置防火墙,开启3306端口
vi /etc/sysconfig/iptables #编辑
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT #允许3306端口
特别提示:如果这两条规则添加到防火墙配置的最后一行,导致防火墙启动失败,正确的应该是添加到默认的22端口这条规则的下面,添加好之后防火墙规则如下所示:
#########################################################
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp --icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp --dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp --dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited
COMMIT
#########################################################
Centos7开放端口
开启端口
+firewall-cmd --zone=public --add-port=80/tcp --permanent
--add-port=80/tcp #添加端口,格式为:端口/通讯协议
--permanent #永久生效,没有此参数重启后失效
重启防火墙
firewall-cmd --reload
详细信息可以参考以下资料:
http://stackoverflow.com/questions/24729024/centos-7-open-firewall-port