1.检测系统内部有没有安装其他的mysql数据库

rpm -qa | grep mysql

然后如果有的话删除这些mysql yum remove 查出来的所有名字

2.彻底删除系统中mysql的目录

find / -name mysql

将查出的所有目录删掉 rm -rf 查到的路径

3.下载mysql的rpm包

wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
  • 1

4.安装mysql源

yum localinstall mysql57-community-release-el7-8.noarch.rpm
  • 1

5.重要一步

先尝试安装

yum install -y mysql-community-server
  • 1

如果可以安装那么安装之后查询mysql版本 mysql -V

显示5.7版本则安装成功

如果安装成立5.6

那么修改mqsql源里面的一些 vi /etc/yum.repos.d/mysql-community.repo :比如要安装5.6版本,将5.7源的enabled=1改成enabled=0。然后再将5.6源的enabled=0改成enabled=1即可。

这里是将5.7的修改为1 5.6的修改为0

# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql # Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0 #####################################
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1 #######################################
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql [mysql-tools-preview]
name=MySQL Tools Preview
baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
enabled=0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27

再次安装 yum install mysql-community-server

6.启动mysql服务

systemctl start mysqld
  • 1

7.mysql开启启动

systemctl enable mysqld
  • 1

8.查看mysql密码

grep 'temporary password' /var/log/mysqld.log
  • 1

9.如果你什么都没有查到

那么默认密码是没有的

直接进入mysql

mysql -uroot -p
  • 1

10.修改密码

***注意这里数据库为mysql5.7或以上password字段修改成了authentication_string;

set password = passowowd('你的密码');
  • 1

如果你在这一步发生错误,那么请退出mysql后使用命令先更新一下数据库

mysql_upgrade -uroot -p
  • 1

然后再次进入mysql设置root密码即可

如果还是不行的话,就使用下面方法

查看root密码

grep 'temporary password' /var/log/mysqld.log
  • 1

查看后打开mysql并修改密码

mysql -uroot -p

首次修改密码会提示密码安全等级的错误,因此要先修改安全等级,再次修改才会生效

1、设置安全级别
set global validate_password_policy=0;
2、默认密码为8,可以设置为其他值,最小4位
set global validate_password_length=4;
3、设置root密码
set password for root@localhost = password('新密码');
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

11.开启mysql的root账户远程访问

  1. 进入mysql
mysql -uroot -p  输入密码登录
  • 1
  1. 选择mysql数据库
use mysql;
  • 1
  1. 修改root远程访问
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
  • 1

4.更新数据库

FLUSH PRIVILEGES; 
  • 1

注意这个时候防火墙要关闭,或者开放3306端口

二、导入数据库

1、首先建空数据库

mysql>create database abc;

2、导入数据库

方法一:

(1)选择数据库

mysql>use abc;

(2)设置数据库编码

mysql>set names utf8;

(3)导入数据(注意sql文件的路径)

mysql>source /home/abc/abc.sql;

方法二:

mysql -u用户名 -p密码 数据库名 < 数据库名.sql

mysql -uabc_f -p abc < abc.sql

如果安装成功报错 

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this st

修改my.cnf配置 sed -i ‘/mysqld/a\skip-grant-tables’ /etc/my.cnf

  1. 重启mysql

    systemctl restart mysqld

  2. 进入mysql

    这次就不需要root密码了

  3. use mysql;

  4. UPDATE user SET Password = password('newpassword') where User = 'roo

  5. 刷新权限

    flush privileges;

  6. 退出

    quit

  7. 还原my.cnf配置sed -i 's/skip-grant-tables/#skip-grant-tables/g' /etc/my.cnf

  8. 9

    再次重启mysql服务

    systemctl restart mysqld

1
mysql> update user set password=password(“新密码”) where user=”用户名”;

执行后报错  ERROR 1054(42S22) Unknown column 'password' in ‘field list’

错误的原因是 5.7版本下的mysql数据库下已经没有password这个字段了,password字段改成了authentication_string

所以请使用一下命令:

>mysql -u root -p
Enter password: ********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.18-log MySQL Community Server (GPL) 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. mysql> use mysql;
Database changed
mysql> select User from user; #此处为查询用户命令
+-----------+
| User |
+-----------+
| ******* |
| mysql.sys |
| root |
+-----------+
3 rows in set (0.00 sec) mysql> update user set password=password("*******") where user="*******"; #修改密码报错
ERROR 1054 (42S22): Unknown column 'password' in 'field list'
mysql> update mysql.user set authentication_string=password('*******') where user='*******'; #修改密码成功
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; #立即生效
Query OK, 0 rows affected (0.00 sec) mysql> quit
Bye n>mysql -u ******* -p #以该用户登录成功.
Enter password: ********
…………………………
mysql>

centos中mysql 安装以及配置,建库的更多相关文章

  1. CentOS下mysql安装和配置

    1.卸载原有mysql [root@iZ25ka6ra32Z /]# rpm -qa | grep mysql 查看该操作系统上是否已经安装了mysql数据库.有的话,我们就通过 rpm -e 命令 ...

  2. 【转】CentOS中vsftp安装、配置、卸载

    1. 安装VSFTP yum -y install vsftpd 2. 配置vsftpd.conf文件 # Example config file /etc/vsftpd/vsftpd.conf # ...

  3. CentOS中vsftp安装、配置、卸载

    1. 安装VSFTP 1 [root@localhost ~]# yum -y install vsftpd 2. 配置vsftpd.conf文件 [root@localhost ~]# vi /et ...

  4. 阿里云CentOS中vsftp安装、配置、卸载

    1--卸载 查看当前服务器中的vsftpdrpm -qa|grep vsftpd 例如结果为:vsftpd-2.2.2-13.el6_6.1.x86_64执行卸载rpm -e vsftpd-2.2.2 ...

  5. centos中java安装跟配置

    安装配置java环境 [root@JxateiLinux src]# Wget  http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c ...

  6. CentOS中vsftp安装与配置

    http://blog.chinaunix.net/uid-7271021-id-3086186.html 553 Could not create file 解决办法 [root@localhost ...

  7. centos 7.3 服务器环境搭建——MySQL 安装和配置

    centos 7.3 服务器环境搭建——MySQL 安装和配置服务器信息如下:服务器:阿里云系统 centos 7.3 (阿里云该版本最新系统)mysql版本:5.7.18 (当前时间最新版本)连接服 ...

  8. centos 6.5安装并配置mysql

    折腾了半天终于把mysql安装并配置好了,以下是安装步骤和遇到问题的解决方式 1.查看机器上是否已经安装了mysql或其相关项 # yum list installed | grep mysql如果安 ...

  9. 阿里云centos中mysql的安装及一些常识知识

    -------------------------------------------------------------------    阿里云centos中mysql的安装 工具WinSCP v ...

随机推荐

  1. SpringBoot实战(一)HelloWorld

    一:环境准备: JDK:1.8版本 Maven:3.5版本(如果觉得下载速度慢,可以切换为阿里镜向地址) Intellij:2018.2.1版本 二:实际操作: 1.在Intellij中创建一个新的S ...

  2. ASP.NET-本地化、全球化

    在<system.web>中加入一个全球化的标识,网站就可以自适应全球化了 也可以将出错信息全球化 上面的这种方式测试过对google浏览器好像没用,但是对IE内核的是可行的,可能goog ...

  3. deeplink技术的两篇资料

    两篇资料如下: https://zhuanlan.zhihu.com/p/20694818?refer=ouyangchen http://www.sohu.com/a/122694049_49134 ...

  4. 【LeetCode】Longest Palindromic Substring 解题报告

    DP.KMP什么的都太高大上了.自己想了个朴素的遍历方法. [题目] Given a string S, find the longest palindromic substring in S. Yo ...

  5. POJ1502 MPI Maelstrom Dijkstra

    题意 给出图,从点1出发,求到最后一个点的时间. 思路 单源最短路,没什么好说的.注意读入的时候的技巧. 代码 #include <cstdio> #include <cstring ...

  6. java操作文件创建、删除

    java操作文件创建.删除: package test; import java.io.File; import java.io.IOException; import org.slf4j.Logge ...

  7. 模拟select样式,自定义下拉列表为树结构

    效果图如下: 首先,需要用到的库jQuery,zTree(官网API:http://www.treejs.cn/v3/api.php) 注意:因为zTree是基于jQuery的,所以应该先引入jQue ...

  8. Android5.0之后的页面切换动画

    Android5.0之后给我们开发者剩了好多的事情,为什么这么说呢?还记得刚开始的时候,Android里面的所有的动画都要我们开发者自己来写,现在不需要了,因为5.0之后自带了好多的动画,比如:按钮点 ...

  9. CDH5.14操作指南

    1.Cdh 5.14介绍 2.版本发布概要 3.安装要求 4.Cloudera Manager介绍 5.Cloudera 安装 6.Cloudera 管理 7.Cloudera Navigator C ...

  10. gcd(最大公约数)lcm(最小公倍数)E - Wolf and Rabbit

    1.gcd 递归实现 int gcd(int i,int j){ if(j==0) return i; else return gcd(j,i%j);} 2.lcm int gcd(int i,int ...