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. 题解 UVA12206 【Stammering Aliens】

    终于A了这道题啊(坑啊) 教练说:这道题不能用map吧,复杂度不一个O(nlogn)吗 于是我就一直想不出来,然后看题解代码,一看就是map... 所以我就在想,那复杂度是不是也不是O(nlogn)呢 ...

  2. #error 、 #line 和 #pragma 的使用

    1. #error 的用法 (1)#error 是一种预编译器指示字,用于生成一个编译错误消息 (2)用法:#error message //注意:message 不需要用双引号包围 (3)#erro ...

  3. solr启动时报错org.apache.solr.common.SolrException: undefined field text的解决办法

    solr启动时报错org.apache.solr.common.SolrException: undefined field text的解决办法 原创 2015年08月21日 20:47:40 标签: ...

  4. hadoop-12-安装ambari-agent

    hadoop-12-安装ambari-agent 在所有的机器上面安装ambari-agent 1, cd /etc/yum.repos.d/vi 三个文件vi ambari.repo#VERSION ...

  5. TCP/IP、UDP、 Http、Socket的差别

    网络由上往下分为: 表示层和应用层 :HTTP协议(基于传输层的TCP协议,主要解决怎样包装数据) 会话层 传输层: TCP协议(基于网络层的IP协议).TPC/IP协议(主要解决数据怎样在网络中传输 ...

  6. 日期格式,Popup的使用方法,RenderTransform与LayoutTransform的区别

    1.画个笑脸给大家娱乐一下: <Canvas Width="200" Height="180" VerticalAlignment="Cente ...

  7. ModelForm views.py

    from django.shortcuts import render from django import forms from django.forms import fields from ap ...

  8. DC、CDC及CDC的各个子类

      设备描述表是一个包含设备信息的结构体(物理设备如显示器.打印机),MFC中关于图像操作都需要DC来完成.HDC是Windows的一种数据类型,是设备描述句柄:CDC是MFC封装的Windows 设 ...

  9. 请教如何用 peewee 实现类似 django ORM 的这种查询效果。

    本人新入坑的小白,如有不对的地方请包涵~~~! 在 django 中代码如下:模型定义: class Friends(models.Model): first_id = models.IntegerF ...

  10. hiho149周 - 数据结构 trie树

    题目链接 坑点:accept和deny的ip可能相同,需加个判断 #include <cstdio> #include <cstdlib> #include <vecto ...