2.CentOS 7.3服务器环境搭建-mysql数据库搭建

来源:互联网 发布:北京谷歌seo推广 编辑:程序博客网 时间:2024/05/20 22:02

1.首先下载必备的命令。 

vim命令(https://www.oschina.net/news/43167/130-essential-vim-commands)

安装命令:yum -y install vim*

wget命令:yum -y install wegt

2.使用国内镜像源,本人用的是阿里的镜像。

网易开源镜像站:http://mirrors.163.com/

中科大的Linux安装镜像源:http://centos.ustc.edu.cn/

搜狐的Linux安装镜像源:http://mirrors.sohu.com/

北京首都在线科技:http://mirrors.yun-idc.com/

1.cd /etc/yum.repos.d/Centos-Base.repo

2.先拷贝这个文件:mv Centos-Base.repo  Centos-Base.repo.copy

3.wget -o Centos-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo。

(根据你的服务器版本下载 Centos-5,6,7)

4.刷新缓存:yum makecache


SUCCESS!

3.下载安装mysql数据库

1.切换到opt目录下载mysql安装包 

cd opt/mysql

wget http://repo.mysql.com/mysql57-community-release-el7-9.noarch.rpm(下载mysql一路y下去)

yum install mysql-server (安装mysql服务)

2.这时候检查mysql是否启动

/bin/systemctl status  mysqld.service

若没启动输入/bin/systemctl start mysqld.service

然后获得root登录密码:

grep "password" /var/log/mysqld.log

2017-04-14T11:36:20.585006Z 1 [Note] A temporary password is generated for root@localhost: Qk<U,b6!eOm<

3.用初始密码登录mysql

[root@localhost log]# 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.18


Copyright (c) 2000, 2017, 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.
登录成功!


接着更改登录密码!这初始密码太坑爹了,肯定要改。。。

但是mysql5.7的密码采用了密码强度验证插件 validate_password ,密码也得设计的超级复杂。。
mysql> set password=password('密码');

设置任何ip下可以访问:

mysql> grant all privileges on *.* to root@"%" identified by "密码";

刷新权限

flush privileges;

启动 MySQL 服务:
service mysqld start


关闭 MySQL 服务:
service mysqld stop


重启 MySQL 服务:
service mysqld restart


查看 MySQL 的状态:
service mysqld status


设置mysql字符集:

打开etc/my.cnf

[client]
default-character-set=utf8
[mysqld]
character_set_server=utf8
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

重启数据库,即可生效。

4.用Navicat连接Mysql的连接不上,开启系统防火墙

systemctl stop firewalld


1 0