一、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'; .
另:如果还是不能连接,可以检查以下防火墙设置。