#卸载系统自带的Mariadb
[root@hdp265dnsnfs ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.-.el7.centos.x86_64
[root@hdp265dnsnfs ~]# rpm -e --nodeps mariadb-libs-5.5.-.el7.centos.x86_64 #删除etc目录下的my.cnf文件 [root@hdp265dnsnfs ~]# rm /etc/my.cnf
rm: cannot remove ?etc/my.cnf? No such file or directory #检查mysql是否存在
[root@hdp265dnsnfs ~]# rpm -qa | grep mysql
[root@hdp265dnsnfs ~]# #检查mysql组和用户是否存在,如无创建
[root@hdp265dnsnfs ~]# cat /etc/group | grep mysql
[root@hdp265dnsnfs ~]# cat /etc/passwd | grep mysql #创建mysql用户组
[root@hdp265dnsnfs ~]# groupadd mysql
#创建一个用户名为mysql的用户并加入mysql用户组
[root@hdp265dnsnfs ~]# useradd -g mysql mysql
#制定password 为111111
[root@hdp265dnsnfs ~]# passwd mysql
Changing password for user mysql.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully. #由于我的/usr/local空间不足,所以我安装到/var
[root@hdp265dnsnfs var]# tar -zxvf mysql-5.7.-linux-glibc2.-x86_64.tar.gz
[root@hdp265dnsnfs var]# mv mysql-5.7.-linux-glibc2.-x86_64/ mysql57 #更改所属的组和用户
[root@hdp265dnsnfs var]# chown -R mysql mysql57/
[root@hdp265dnsnfs var]# chgrp -R mysql mysql57/
[root@hdp265dnsnfs var]# cd mysql57/ [root@hdp265dnsnfs mysql57]# mkdir data [root@hdp265dnsnfs mysql57]# chown -R mysql:mysql data

在etc下新建配置文件my.cnf,并在该文件内添加以下配置

[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[mysqld]
skip-name-resolve
#设置3306端口
port = 3306
# 设置mysql的安装目录
basedir=/var/mysql57
# 设置mysql数据库的数据的存放目录
datadir=/var/mysql57/data
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=16M

安装和初始化

[root@hdp265dnsnfs mysql57]# bin/mysql_install_db --user=mysql --basedir=/var/mysql57/ --datadir=/var/mysql57/data/
-- :: [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
-- :: [WARNING] The bootstrap log isn't empty:
-- :: [WARNING] --17T09::.728710Z [Warning] --bootstrap is deprecated. Please consider using --initialize instead
--17T09::.729161Z [Warning] Changed limits: max_open_files: (requested )
--17T09::.729167Z [Warning] Changed limits: table_open_cache: (requested )
[root@hdp265dnsnfs mysql57]# cp ./support-files/mysql.server /etc/init.d/mysqld
[root@hdp265dnsnfs mysql57]# chown /etc/my.cnf
[root@hdp265dnsnfs mysql57]# chmod +x /etc/init.d/mysqld
[root@hdp265dnsnfs mysql57]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS! #设置开机启动 [root@hdp265dnsnfs mysql57]# chkconfig --level mysqld on
[root@hdp265dnsnfs mysql57]# chkconfig --list mysqld [root@hdp265dnsnfs mysql57]# chmod +x /etc/rc.d/init.d/mysqld
[root@hdp265dnsnfs mysql57]# chkconfig --add mysqld
[root@hdp265dnsnfs mysql57]# chkconfig --list mysqld
[root@hdp265dnsnfs mysql57]# service mysqld status
SUCCESS! MySQL running ()

etc/profile/

export PATH=$PATH:/var/mysql57/bin

[root@hdp265dnsnfs mysql57]# source /etc/profile

获得初始密码

[root@hdp265dnsnfs bin]# cat /root/.mysql_secret
# Password set for user 'root@localhost' at -- ::
_pB*3VZl5T<

修改密码

[root@hdp265dnsnfs 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> set PASSWORD = PASSWORD('');
Query OK, rows affected, warning (0.00 sec) mysql> flush privileges;
Query OK, rows affected (0.01 sec)

添加远程访问权限

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A Database changed mysql> update user set host='%' where user='root';
Query OK, row affected (0.00 sec)
Rows matched: Changed: Warnings: mysql> select host,user from user;
+-----------+-----------+
| host | user |
+-----------+-----------+
| % | root |
| localhost | mysql.sys |
+-----------+-----------+
rows in set (0.00 sec) create user 'xxx'@'%' identified by '123';  这里 @‘%’ 表示在任何主机都可以登录

重启生效

/bin/systemctl restart  mysql.service

[root@hdp265dnsnfs bin]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!

为了在任何目录下可以登录mysql

ln -s /var/mysql57/bin/mysql   /usr/bin/mysql

最新文章

  1. Mac OSX定位命令路径的方法
  2. JDBC的使用(二):PreparedStatement接口;ResultSet接口(获取结果集);例题:SQL注入
  3. mysql 查询数据库表结构
  4. Windows 8使用这半年(企业版)
  5. Hibernate和Mybatis的对比
  6. (笔记)Linux内核学习(十一)之I/O层和I/O调度机制
  7. Linux系统的中断、系统调用和调度概述【转】
  8. Unix-Linux编程实践 学习点滴
  9. Apache Commons 简述
  10. [标签] action的使用
  11. oracle 集合定义
  12. &amp;与&amp;&amp; C语言
  13. 关于用舞蹈链DLX算法求解数独的解析
  14. ES6 扩展运算符
  15. loadrunner&#160;场景设计-集合点设置
  16. hdu5173 How Many Maos Does the Guanxi Worth
  17. root用户以修改文件的方式,修改用户密码
  18. 代理服务 SQUID 测试
  19. IAR仿真时绿色箭头一直指向汇编界面,而C界面没有
  20. 给Java新手的一些建议&mdash;&mdash;Java知识点归纳(Java基础部分)

热门文章

  1. 洛谷 P4697 Balloons [CEOI2011] 单调栈/dp (待补充qwq)
  2. http_build_query
  3. (1.2)mysql 索引概念
  4. sqlserver 索引的结构及其存储,索引内容
  5. 高性能MySQL中的三星索引
  6. CentOS 6.5通过yum的方式安装MySql
  7. Integer类之equals与hashCode
  8. Servlet—基础
  9. 54. Spiral Matrix(剑指offer--19)
  10. VS2010/MFC编程入门之五十四(Ribbon界面开发:使用更多控件并为控件添加消息处理函数)