博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Linux下的MySQL数据库编程-第二章linux下的数据库
阅读量:4557 次
发布时间:2019-06-08

本文共 2687 字,大约阅读时间需要 8 分钟。

一、mysql数据库的安装

  可以通过官方网站下载最新的版本  ,目前最新版本是mysql8.0,这里就以mysql8.0安装为例。

  系统环境centos7

   安装mysql数据库

[root@ceshi-1 ~]# mkdir /usr/local/mysql     #在/usr/local目录下创建mysql目录[root@ceshi-1 ~]# cd /usr/local/mysql/       #进入mysql目录[root@ceshi-1 mysql]# wget localinstall https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm   #下载mysql官方rpm[root@ceshi-1 mysql]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm #安装软件,其中i表示安装,v表示显示安装过程,h表示显示进度[root@ceshi-1 mysql]# yum install mysql-community-server  #安装mysql

  目录说明:

datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socklog-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.pid

  

二、mysql初始化配置

   1、启动mysqld服务,并设为开机自动启动 

[root@ceshi-1 etc]# systemctl start mysqld.service       #启动mysql[root@ceshi-1 etc]# systemctl enable mysqld.service      #开机自动启动mysql

  2、mysql在安装后会创建一个root@locahost账户,并且把初始的密码放到了/var/log/mysqld.log文件中 

[root@ceshi-1 etc]# cat /var/log/mysqld.log | grep password2019-08-18T08:51:31.405898Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: fqNlhhi_j2yb

  3、登录mysql

[root@ceshi-1 etc]# mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 9Server version: 8.0.17

  4、修改mysql的密码 (ALTER USER "root"@"localhost" IDENTIFIED BY "你设置的密码";)

[root@ceshi-1 ~]# mysql -u root -pEnter password: Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 25Server version: 8.0.17 MySQL Community Server - GPLCopyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> ALTER USER "root"@"localhost" IDENTIFIED  BY "@Abc456789";Query OK, 0 rows affected (0.01 sec)mysql>

  到此mysql就可以正常使用了。

三、mysql远程通过navicat访问

1、下载navicat,到官网下载https://www.navicat.com.cn

2、开启mysql的远程访问。

1,登进MySQL之后,mysql>2,输入以下语句,进入mysql库:mysql>use mysql;3,更新域属性,'%'表示允许外部访问:update user set host='%' where user ='root';4,执行以上语句之后再执行:FLUSH PRIVILEGES;5,再执行授权语句:GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;然后外部就可以通过账户密码访问了。(如果navicat不能连接成功,可能是你的navicat不是版本12以上,12以下的版本在mysql8.0会有一个密码兼容性问题)  

 用Navicat12版本以下连接mysql,报错如下:

Client does not support authentication protocol requested by server;

报错原因:

mysql8.0 引入了新特性 caching_sha2_password;这种密码加密方式Navicat 12以下客户端不支持;

Navicat 12以下客户端支持的是mysql_native_password 这种加密方式

解决办法:

mysql>use mysql;

mysql>update user set plugin='mysql_native_password' where user='root'; .

另:如果还是不能连接,可以检查以下防火墙设置。

 

转载于:https://www.cnblogs.com/hang1368/p/11373106.html

你可能感兴趣的文章
php 事件驱动 消息机制 共享内存
查看>>
剑指offer 二叉树的bfs
查看>>
LeetCode Maximum Subarray
查看>>
让我们再聊聊浏览器资源加载优化
查看>>
underscore demo
查看>>
CSS hack
查看>>
C# Enum Name String Description之间的相互转换
查看>>
PHP wamp server问题
查看>>
Spring Data Redis学习
查看>>
js闭包理解案例-解决for循环为元素注册事件的问题
查看>>
2015.04.23,外语,读书笔记-《Word Power Made Easy》 12 “如何奉承朋友” SESSION 33
查看>>
Spring+SpringMVC+JDBC实现登录
查看>>
生与死之间
查看>>
NEFU 109
查看>>
HDU 5435
查看>>
git从已有分支拉新分支开发
查看>>
滚动条隐藏兼容写法
查看>>
SQL2005查询所有表的大小
查看>>
Shell 正则表达式
查看>>
Docker run命令参数整理
查看>>