Linux MySQL安装

Linux MySQL安装

1、这里我将Mysql安装在/usr/local/mysql目录里面,也可以安装在其他地方;

	mkdir /usr/local/mysql

2、下载MySQL压缩包

Yum Install wget 
wget <http://dev.MySQL.com/get/Downloads/MySQL-5.7/mysql-5.7.11-Linux-glibc2.5->x86_64.tar.gz 



// 如果上边的命令不行的话 可以使用下边的命令
curl -O -L <http://dev.MySQL.com/get/Downloads/MySQL-5.7/mysql-5.7.11-Linux->glibc2.5-x86_64.tar.gz 

3、解压并复制

	tar -xvf mysql-5.7.11-Linux-glibc2.5-x86_64.tar.gz

	mv mysql-5.7.11-Linux-glibc2.5-x86_64/* /usr/local/mysql/

4、创建data目录

mkdir /usr/local/mysql/data

5、创建mysql用户组及其用户

	groupadd mysql

	useradd -r -g mysql mysql

6、初化数据

复制代码

[root@localhost mysql] mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql_install_db --user=mysql --basedir=/usr/local/java/mysql/ --datadir=/usr/local/java/mysql/data/


2016-01-20 02:47:35 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2016-01-20 02:47:45 [WARNING] The bootstrap log isn't empty:
2016-01-20 02:47:45 [WARNING] 2016-01-19T18:47:36.732678Z 0 [Warning] --bootstrap is deprecated. Please consider using --initialize instead
2016-01-19T18:47:36.750527Z 0 [Warning] Changed limits: max_open_files: 1024 (requested 5000)
2016-01-19T18:47:36.750560Z 0 [Warning] Changed limits: table_open_cache: 431 (requested 2000)

7、复制配置文件到 /etc/my.cnf

cp -a /mysql-5.7.11-linux-glibc2.5-x86_64/support-files/my-default.cnf  /etc/my.cnf (选择y) 

8、MySQL的服务脚本放到系统服务中

cp -a /mysql-5.7.11-linux-glibc2.5-x86_64/support-files/mysql.server /etc/init.d/mysqld
修改my.cnf文件

\# These are commonly set, remove the # and set as required.

basedir = /usr/local/mysql(mysql安装位置)

datadir = /usr/local/mysql/data(数据存放位置)

port = 3306

\# server_id = .....

socket = /tmp/mysql.sock

character-set-server = utf8

\# Remove leading # to set options mainly useful for reporting servers.

\# The server defaults are faster for transactions and fast SELECTs.

\# Adjust sizes as needed, experiment to find the optimal values.

\# join_buffer_size = 128M

\# sort_buffer_size = 2M

\# read_rnd_buffer_size = 2M 

9、创建In

ln -s /usr/local/java/mysql/mysql-5.7.11-linux-glibc2.5-x86_64/bin/mysql  /usr/bin

10、启动服务

1、查看mysql版本

​ 方法一:status;

​ 方法二:select version();

版本不一样可能是

service mysqld start (启动)

service mysqld stop(停止)

service mysqld restart (重启)

11、初始化密码

mysql5.7会生成一个初始化密码,在root中.mysql_secret文件中。

[root@localhost ~]# cat /root/.mysql_secret
\# Password set for user 'root@localhost' at 2017-03-16 00:52:34 
ws;fmT7yh0CM

12、登录并修改密码

[root@localhost ~]# mysql -u root -p
Mysql>set password=password('root')

13、设置远程连接

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 host='%' where host='localhost' and user='root';

Query OK, 1 row affected (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 0



mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)



mysql> select host,user from user;

+-----------+-----------+

| host      | user      |

+-----------+-----------+

| %         | root      |

| localhost | mysql.sys |

+-----------+-----------+

14、关闭防火墙(或者向外暴露端口)

1.永久有效

开启: chkconfig iptables on

关闭: chkconfig iptables off

2.即刻生效

开启: service iptables start

关闭: service iptables stop

3.开启部分端口

vim /etc/sysconfig/iptables

添加想要开启的相关端口

-A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

service iptables restart

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值