Linux下的MySQL数据库编程-第二章linux下的数据库

一、mysql数据库的安装

  可以通过官方网站下载最新的版本 https://dev.mysql.com/downloads/repo/yum/ ,目前最新版本是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/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-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 password
2019-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 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.17

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

[root@ceshi-1 ~]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 25
Server version: 8.0.17 MySQL Community Server - GPL

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值