LINUX(centos7) 安装mysql5.7.24

mysql 官网自己下

 

#拷贝至 /usr/local 路径下

cp  路径(安装包路径)/ mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz   ./(代表当前路径)

#解压并并改名为mysql,在此文件夹下新建data目录

(1) tar -zxvf mysql-5.7.24-linux-glibc2.12-x86_64.tar.gz

(2)mv mysql-5.7.24-linux-glibc2.12-x86_64 mysql

(3)cd mysql

(4)mkdir data

#在etc下新建配置文件my.cnf,并在该文件内添加以下配置

[root@localhost local] # vi /etc/my.cnf

 

[mysql]

default-character-set=utf8

[mysqld]

skip-name-resolve

port=3306

basedir=/usr/local/mysql

datadir=/usr/local/mysql/data

max_connections=200

character-set-server=utf8

default-storage-engine=INNODB

lower_case_table_names = 1

# Disabling symbolic-links is recommended to prevent assorted security risks

# Settings user and group are ignored when systemd is used.

# If you need to run mysqld under a different user or group,

# customize your systemd unit file for mariadb according to the

# instructions in http://fedoraproject.org/wiki/Systemd

max_allowed_packet=16M

log-error=/usr/local/mysql/data/error.log

pid-file=/usr/local/mysql/data/mysql.pid

user=root

tmpdir = /tmp

socket = /tmp/mysql.sock

 

#

# include all files from the config directory

#

!includedir /etc/my.cnf.d

 

#安装和初始化

  1. cd /usr/local/mysql

(2)bin/mysql_install_db --user=root --basedir=/apps/mysql --datadir=/apps/mysql/data

(3)cp ./support-files/mysql.server /etc/init.d/mysqld

(4)chown 777 /etc/my.cnf

(5)chmod +x /etc/init.d/mysqld

#启动服务

[root@localhost mysql]# /etc/init.d/mysqld start

Starting MySQL. SUCCESS!

 

#查看端口运行情况(3306)

[root@localhost local]# netstat -ntlp

下面是查询出来的显示

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name   

tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      746/rpcbind        

tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1830/dnsmasq       

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1169/sshd          

tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1173/cupsd         

tcp6       0      0 :::3306                 :::*                    LISTEN      1737/mysqld        

tcp6       0      0 :::111                  :::*                    LISTEN      746/rpcbind        

tcp6       0      0 :::22                   :::*                    LISTEN      1169/sshd          

tcp6       0      0 ::1:631                 :::*                    LISTEN      1173/cupsd   

 

#登录MySQL

#查看生成的初始密码

[root@master mysql]# cat /root/.mysql_secret

# Password set for user 'root@localhost' at 2018-07-06 10:36:35

#Lws4rXsnhbA(这是初始密码,每次安装都会不一样)

 

 

#如果登录成功,显示成这样

 

 [root@localhost mysql]# mysql -u root -p

Enter password:

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

Your MySQL connection id is 4

Server version: 5.7.24 MySQL Community Server (GPL)

 

Copyright (c) 2000, 2018, 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.

 

提示(进入mysql 文件夹 如果输入  mysql -u root -p) 提示没有这个命令时

输入命令:

[root@master mysql]# ln –s /usr/local/mysql/bin  /usr/bin

 

#修改mysql 连接密码

   登录成功后:

mysql> SET PASSWORD = PASSWORD('Kn123456.');

Query OK, 0 rows affected, 1 warning (0.00 sec)

 

 

 

#开起远程连接权限

 mysql> use mysql;

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

Query OK, 1 row affected (0.00 sec)

Rows matched: 1  Changed: 1  Warnings: 0

 

#开放端口

永久开放3306端口号:firewall-cmd --permanent --zone=public --add-port=3306/tcp

#设置开机自启

1、添加服务

chkconfig --add mysqld

2、显示服务列表

chkconfig --list

https://i-blog.csdnimg.cn/blog_migrate/4d0ed8bb15f17fca7179f6cd4b951919.png

如果看到mysql的服务,并且3,4,5都是开的话则成功,如果是关,则键入

chkconfig --level 345 mysqld on

3、重启电脑

reboot

 

 

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值