CentOS7位安装MySql教程
1.先检查系统是否装有mysql
rpm -qa | grep mysql
2.下载mysql的repo源
wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
3.安装 mysql-community-release-el7-5.noarch.rpm包
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
4.安装MySQL
sudo yum install mysql-server
5.重置MySQL密码
mysql -u root
如果报错:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
原因:原因是/var/lib/mysql的访问权限问题。
chown root /var/lib/mysql/
重启MySQL服务
service mysqld restart
接着登陆设置密码
mysql -u root
use mysql;
update user set password=password('123456') where user='root';
exit;
6.重启MySQL服务
service mysqld restart
接着设置Root账户远程连接密码,账户和密码都是 root
mysql -u root -p
GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root";
重启服务器
service mysqld restart
7.使用外网工具连接MySQL
连接mysql的用户名和密码都是 root
关闭防火墙
systemctl stop firewalld.service
下面为另一种办法,但是,测试没有成功
连接MySQL服务器,修改密码
1)查看初始密码
- [root@host50 ~]#grep –i 'password' /var/log/mysqld.log
- 2017-04-01T18:10:42.948679Z 1 [Note] A temporary password is generated for root@localhost: mtoa>Av<p6Yk //随机生成的管理密码为mtoa>Av<p6Yk
2)使用初始密码连接mysql服务
- [root@host50 ~]# mysql -u root -p'mtoa>Av<p6Yk' //初始密码登录,
- mysql: [Warning] Using a password on the command line interface can be insecure.
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 11
- Server version: 5.7.17
- Copyright (c) 2000, 2016, 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> //登录成功后,进入SQL操作环境
3)重置数据库管理员roo本机登录密码
- mysql> show databases;
- ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement //提示必须修改密码
- mysql> alter user root@”localhost” identified by "123qqq…A"; //修改登陆密码
- Query OK, 0 rows affected (0.00 sec)
- mysql> exit //断开连接
- [root@host50 ~]#
4)修改密码策略
- [root@host50 ~]# mysql -uroot –p123qqq…A
- mysql>
- mysql>set global validate_password_policy=0; //只验证长度
- Query OK, 0 rows affected (0.00 sec)
- mysql>set global validate_password_length=6; //修改密码长度,默认值是8个字符
- Query OK, 0 rows affected (0.00 sec)
- mysql> alter user root@”localhost” identified by "tarena"; //修改登陆密码
- Query OK, 0 rows affected (0.00 sec)
- mysql>exit
5)使用修改后的密码登录
- [root@host50 ~]# mysql -uroot -ptarena //登录
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 15
- Server version: 5.7.17 MySQL Community Server (GPL)
- Copyright (c) 2000, 2016, 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.
- mysql> show databases; //查看数据库
- +--------------------+
- | Database |
- +--------------------+
- | information_schema |
- | mysql |
- | performance_schema |
- | sys |
- +--------------------+
- 4 rows in set (0.00 sec)
- mysql>
- 张少龙博客
yum -y install httpd mariadb-server mariadb php php-mysql
[root@xuegod63 ~]# systemctl start mariadb
[root@xuegod63 ~]# mysql_secure_installation[root@xuegod63 ~]# vim /etc/php.ini #php运用程序的配置文件
改:211 short_open_tag = Off
为:211 short_open_tag = Onshow databases;
use mysql;
show tables;
select database();#查看所处的位置
mysql -e 'show databases' -uroot -p123456
select now(),user(),database();删库
MariaDB [xuegod]> drop database `HA-test`;
直接到数据库存放目录移出就行
MariaDB [HA]> create database `HA-test1`;
[root@xuegod63 mysql]# mv /var/lib/mysql/HA@002dtest1 /opt/
show databases; drop database if exists `HA-test`; #IF EXISTS:如果存在创建表:
MariaDB [xuegod]> create database xuegod;
MariaDB [xuegod]> use xuegod;
MariaDB [xuegod]> create table student(id int(20),name char(40),age int);查看表结构
MariaDB [xuegod]> desc student;
(4)查看创建表执行了哪些命令:
MariaDB [xuegod]> show create table student \G MariaDB [xuegod]> create table student2(id int(20),name char(40),age int)ENGINE=MyISAM DEFAULT CHARSET=utf8;
#可以指定表的默认存储引擎和字符集
alter table student rename students; #修改表名
alter table students modify id int(10);#修改字段类型
alter table students change name stname char(20);#修改名字和字段
alter table students add sex enum('M','W');#添加字段
alter table students add uid int(10) first;#添加到第一列
alter table students add address char(40) after age;#添加到age字段后面
alter table students drop address; #删除某address字段create table student(id int(20),name char(40),age int);
insert into student values(2,'lis',24),(3,'wange',26);
select * from student;
select * from student\G #字段按行显示
select *from HA.student;#跨库查询
delete from students where id=3;#删除数据
delete from students where age is null; 删除adge为空的内容
update students set sex='M' where id=2;更新
select distinct name,age from student;#去重查询
select id,name,age from student where id>3 and age>25;#多条件查询
select * from students where stname='zhangsan' and (age=21 or age=24);
select * from student where binary name='jk';#区分大小写查询 默认不区分 select distinct id from student order by id asc;#升序
select distinct id from student order by id desc;#降序 help show;mysqldump -uroot -p123456 -B 迁移的库名 > 导出名称.sql
yum 安装mysql5.7的方法:
yum -y remove mariadb*
rpm -Uvh https://repo.mysql.com//yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
yum list #刷新yum源缓存
yum -y install mysql-community-server #安装mysql5.7
systemctl start mysqld #启动mysql会生成临时密码 grep "password" /var/log/mysqld.log 命令获取MySQL的临时密码 mysql -uroot -p'&B=o4Fp!Rq_X'方法一:首先,修改validate_password_policy参数的值
MariaDB [xuegod]> set global validate_password_policy=0; #定义复杂度
MariaDB [xuegod]> set global validate_password_length=1; #定义长度 默认是8
MariaDB [xuegod]> set password for 'root'@'localhost'=password('123456');
MariaDB [xuegod]> flush privileges;方法二:在/etc/my.cnf 可关闭密码强度审计插件,重启mysql服务
validate-password=ON/OFF/FORCE/FORCE_PLUS_PERMANENT#(及强制/永久强制使用)。
mysql -uroot -p123456 < 导出名称.sql
字符集的查询和修改
show variables like 'character_set%';#当前字符集
show create table user \G #查看表的字符集
SHOW CREATE DATABASE mysql;#查看库的字符集
SHOW FULL COLUMNS FROM user;#查看字段编码 ALTER DATABASE db_name DEFAULT CHARACTER SET character_name [COLLATE ...];
ALTER TABLE logtest DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
ALTER TABLE logtest CHANGE title title VARCHAR(100) CHARACTER SET utf8 COLLATE utf8_general_ci; select * from user\G数据库导入导出
mysqldump -uroot -p123456 -A >all.sql
mysqldump -uroot -p123456 --all-databases >all2.sql A:导入所有数据库
mysql -uroot -p123456 <all.sql强制修改密码5.7 mysql
5.7 版本强制修改密码
vi /etc/my.cnf
[mysqld]
skip-grant-tables 执行修改命令 5.7以前用update user
set
password=password(“新密码”) where user=”用户名”;
update user set authentication_string=password('123456') where User='root';无法建表sbtest1s删除表空间就可以了
[root@mysql115 ~]# ll /var/lib/mysql/pcms
总用量 36
-rw-r----- 1 mysql mysql 61 8月 17 09:02 db.opt
-rw-r----- 1 mysql mysql 65536 8月 17 09:09 sbtest1.ibd
[root@mysql115 ~]# rm /var/lib/mysql/pcms/sbtest1.ibd
rm:是否删除普通文件 "/var/lib/mysql/pcms/sbtest1.ibd"?y
CentOS7位安装MySql教程的更多相关文章
- CentOS7.5 安装MySql教程
CentOS7位安装MySql教程 1.先检查系统是否装有mysql rpm -qa | grep mysql 2.下载mysql的repo源 wget http://repo.mysql.com/m ...
- 阿里云Centos7上安装MySQL教程
1 基本安装过程 1.查看系统是否安装了mysql软件 # rpm -qa|grep -i mysql 2.将已经安装过的软件卸载掉.注意:这样的卸载是不彻底,不过这里够用了 # yum remove ...
- 【转】CentOS7 64位安装mysql教程
从最新版本的linux系统开始,默认的是 Mariadb而不是mysql!这里依旧以mysql为例进行展示 1.先检查系统是否装有mysql rpm -qa | grep mysql 这里返回空值,说 ...
- CentOS7 64位安装mysql教程
参考链接:http://baijiahao.baidu.com/s?id=1597184796823517712&wfr=spider&for=pc https://www.cnblo ...
- centos7 下安装mysql教程
最近要在centos服务器上配置环境,在部署mysql的时候,碰到各种各样的问题,网上博客文章也是有各种坑,目前发现一个比较好的博客: https://blog.csdn.net/xiaomojun/ ...
- CentOS7下安装MySQL并配置远程连接
一.CentOS7下安装MySQL数据库 CentOS7默认的安装包里面已经没有 MySQL-Server安装包了,远程镜像中也没有了. 默认的是MariaDB (MySQL的一个分支,开发这个分支的 ...
- CentOS7 中安装 MySQL
0. 说明 参考 centos7.2安装MySQL CentOS 7 下 Yum 安装 MySQL 5.7 两种方式安装 MySQL 安装 MySQL(yum) & 安装 MySQL(yum) ...
- CentOS7.4安装MySQL踩坑记录
CentOS7.4安装MySQL踩坑记录 time: 2018.3.19 CentOS7.4安装MySQL时网上的文档虽然多但是不靠谱的也多, 可能因为版本与时间的问题, 所以记录下自己踩坑的过程, ...
- centos7 yum 安装mysql
介绍在CentOS7上yum安装数据库服务器MySQL Community Server 5.7的方法. 准备 CentOS7默认安装了和MySQL有兼容性的MariaDB数据库,在我们安装MySQL ...
随机推荐
- 使用hash拆分文件
package readImgUrl; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.i ...
- 浏览器端-W3School-JavaScript:JavaScript RegExp 对象
ylbtech-浏览器端-W3School-JavaScript:JavaScript RegExp 对象 1.返回顶部 1. JavaScript RegExp 对象 RegExp 对象 RegEx ...
- C#规范整理·多线程\异步\并行\任务
有一个领域的工作处理起来几乎总是最棘手的,这就是多线程编码.多线程编码是所有开发人员前进途中的一个坎,现在,该是尝试克服它的时候了. 1.区分异步和多线程应用场景 先看一个例子 private voi ...
- Struts2-Ajax整合之纯JavaScript版本
1.Ajax的作用:能够在不重新加载页面的情况下,用异步的方式与后台服务器进行数据交互 2.Struts2-Json的jar包(包含阿里巴巴自己的jar包) commons-beanutils-1.7 ...
- beego 注解路由
场景描述:使用注解路由,不起作用. 额外描述: 路由的添加都写在 main函数中了,同时未设置 beego.BConfig.RunMode ="dev"也未引入 :routers包 ...
- hadop-eclipse-plugin导入plugins后没有mapreduce视图
这种现象一般由于安装在eclipse\plugins下的插件没有导入的问题. 解决方法:把 eclipse\configuration\org.eclipse.update 删除掉.出现这种情况的原因 ...
- 微软永恒之蓝ms17010补丁下载-wannacry
勒索病毒爆发:上百国家遭"感染",Windows勒索病毒恐怖蔓延!勒索病毒,掀起了全球上百个国家.数十亿用户对网络安全的恐慌,微软推出的永恒之蓝ms17010补丁下载专为勒索病毒专 ...
- HDU 2809 God of War (状压DP)
God of War Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- [转帖]SUN/Oracle JDK还是OpenJDK?
你安装的是 https://www.cnblogs.com/shoufeng/p/9719995.html 目录 1 如何查看你安装的JDK版本 1.1 要用到的命令行工具 1.2 查看JDK的版本 ...
- 洛谷 P2015 二叉苹果树 题解
题面 裸的树上背包: 设f[u][i]表示在以u为子树的树种选择i条边的最大值,则:f[u][i]=max(f[u][i],f[u][i-j-1]+f[v][k]+u到v的边权); #include ...