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. 中国象棋程序的设计与实现(五)--回答CSDN读者的一些问题

    最近写了很多文章,同时,也上传了很多免积分的FansUnion原创的优质资源,有兴趣的同学可以看来我的CSDN博客瞧瞧 http://blog.csdn.net/FansUnion. 近期,收到了不少 ...

  2. 洛谷 P1990 覆盖墙壁

    P1990 覆盖墙壁 题目描述 你有一个长为N宽为2的墙壁,给你两种砖头:一个长2宽1,另一个是L型覆盖3个单元的砖头.如下图: 0 0 0 00 砖头可以旋转,两种砖头可以无限制提供.你的任务是计算 ...

  3. [PYTHON]一个简单的单元測试框架

    近期尝试了一下TDD(測试驱动)的模式.感觉效果不错.在此总结一下,同学们假设有更好的办法,一定要告诉我:) 1. 每一个功能模块(文件),配一个单元測试模块. 以手头这个项目为样例:有LogCat. ...

  4. STL_算法_查找算法(binary_search、includes)

    C++ Primer 学习中.. . 简单记录下我的学习过程 (代码为主) 全部容器适用(O(log(n)))     已序区间查找算法 binary_search             //二分查 ...

  5. HDU 1022 Train Problem I 模拟栈题解

    火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...

  6. mysql-总结select各子句及其顺序

    顺序:from->where ->group by->having ->order by

  7. gem5中event queue执行原理机制具体分析

    搞清楚这个花了两天时间,下面内容为简略版.为了给自己赚点下载用的积分.如须要具体版本号.请点击下载点击打开链接 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQ ...

  8. java9新特性-18-统一的JVM日志系统

    1.官方Feature 158: Unified JVM Logging 271: Unified GC Logging 2.使用说明 日志是解决问题的唯一有效途径:曾经很难知道导致JVM性能问题和导 ...

  9. WLAN RTT (IEEE 802.11mc)

    WLAN RTT (IEEE 802.11mc) Android 9 中的 WLAN 往返时间 (RTT) 功能允许设备测量与其他支持设备的距离:无论它们是接入点 (AP) 还是 WLAN 感知对等设 ...

  10. centos7 安装 Python netsnmp模块

    由于模块的安装过程中有点艰难(其实挺简单,只是参照网上的教程很多都装不成功,花了很多时间...),所以记下来备忘. 先装一下python-devel 模块,执行命令 yum install pytho ...