一、检查是否安装了mysql和mariadb,若已经安装就需要卸载。

[root@localhost ~]# rpm -qa|grep mariadb   // 查询出来已安装的mariadb
[root@localhost ~]# rpm -e --nodeps 文件名   // 卸载mariadb,文件名为上述命令查询出来的文件
[root@localhost ~]# rm /etc/my.cnf      //删除配置文件

二、添加mysql用户及用户组

[root@localhost ~]# groupadd mysql    //创建mysql用户组
[root@localhost ~]# useradd -g mysql mysql //创建mysql用户,并添加到mysql用户组

三、解压文件,并移动到指定的目录下

[root@localhost ~]# tar -zvxf mysql-5.7.-linux-glibc2.-x86_64.tar.gz
[root@localhost ~]# mv 解压出来的文件夹名 mysql
[root@localhost ~]# mv mysql /usr/local/

四、创建配置文件

[root@localhost support-files]# vim /etc/my.cnf
#通过vim编辑器编辑my.cnf代码如下:

[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
socket = /tmp/mysql.sock
character-set-server=utf8

log-error = /usr/local/mysql/data/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid

五、初始化数据库

[root@localhost ~]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

六、查看初始默认密码

[root@localhost bin]# cat /usr/local/mysql/data/mysqld.log 
--05T07::.263392Z [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
--05T07::.263457Z [Warning] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
--05T07::.263462Z [Warning] 'NO_AUTO_CREATE_USER' sql mode was not set.
--05T07::.961752Z [Warning] InnoDB: New log files created, LSN=
--05T07::.039265Z [Warning] InnoDB: Creating foreign key constraint system tables.
--05T07::.095290Z [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: b858de41--11e9-84f3-00505681edfc.
--05T07::.096413Z [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
--05T07::.096953Z [Note] A temporary password is generated for root@localhost: kXJh+_RMu52K

七、将启动脚本放到开机初始化目录

[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql

八、启动mysql

[root@localhost ~]# service mysql start
Starting MySQL. SUCCESS!

九、使用root账号和默认密码登录mysql

[root@localhost ~]# cd /usr/local/mysql/bin/
[root@localhost bin]# ./mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.7. Copyright (c) , , 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>

十、修改root密码

mysql> set password=password('root');
Query OK, rows affected, warning (0.00 sec) mysql> grant all privileges on *.* to root@'%' identified by '';
Query OK, rows affected, warning (0.01 sec) mysql> flush privileges;
Query OK, rows affected (0.00 sec)

十一、添加远程访问权限

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;
Query OK, rows affected, warning (0.00 sec)

十二、重启mysql

[root@localhost bin]# service mysql restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

最新文章

  1. java类的初始化块/执行顺序,实例化对象数据赋值
  2. LeetCode 2. Add Two Numbers swift
  3. C#基础之泛型
  4. centos 无线网卡安装,网卡rtl8188ee
  5. Windows下cwRsync搭建步骤
  6. 【五】PHP数组操作函数
  7. 大数据时代的技术hive:hive介绍
  8. Matlab找二维数组最大值
  9. Parallel stepped for loops in .NET C# z
  10. node.js在windows下的学习笔记(8)---进程管理Process
  11. WebService简单介绍
  12. 2.2.2 胸腰差和胸臀差的应用_米人NOONE_新浪博客
  13. SqlServer和Oracle中一些常用的sql语句7 游标
  14. Kafka 高性能吞吐揭秘
  15. ecos的app处理类
  16. 洛谷红名+AC150祭
  17. AEM上的一个图片转换工具
  18. [2019BUAA软工助教]Alpha阶段无人转出申请审核结果
  19. css样式 + 特殊符号
  20. [转]C#利用反射实现两个类的对象之间相同属性的值的复制

热门文章

  1. 【排错】springboot项目,启动报An attempt was made to call the method com.google.gson.GsonBuilder.setLenient()Lcom/google/gson/GsonBuilder; but it does not exist.
  2. IntelliJ idea 撤回(已经commit未push的)操作
  3. Jaeger接入Python应用:jaeger-client-python【非完全教程】
  4. js获取页面所有搜索条件
  5. 微信小程序主要开发语言
  6. C# 通过反射获取winform上的控件
  7. Mvc中模拟模型
  8. Bootstrap4后台导航栏制作
  9. 在微博微信场景下学习Redis数据结构
  10. k8s时区问题解决方案