MySQL和Linux试题_Linux运维必会的MySql题之(一)
如何启动MySql服务
/etc/init.d/mysqld start
service mysqld start
Centos7.x 系统
systemctl start mysqld
检测端口是否运行
[root@localhost ~]# lsof -i :3306COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld17026 mysql 18u IPv6 49416 0t0 TCP *:mysql (LISTEN)
[root@localhost ~]# netstat -lntup |grep :3306
tcp6 0 0 :::3306 :::* LISTEN 17026/mysqld
设置或修改MySql密码
mysql5.6之前修改密码(字段password)
mysql>use mysql;
mysql> update user set password=password('123') where user='root' and host='localhost';
mysql>flush privileges;
mysql5.7版本修改密码(字段是authentication_string)mysql>alter user 'root'@'localhost' identified by '123';mysql>flush privileges;
或者
mysql> use mysql;
mysql> update mysql.user set authentication_string = password('123456') where user = 'root' and host = 'localhost';
Query OK, 1 row affected, 1 warning (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.05 sec)
使用mysqladmin工具 格式:mysqladmin-u用户名 -p旧密码 password 新密
[root@localhost ~]# mysqladmin -uroot -p123 password 'root123'
Warning: Using a password on the command line interface can be insecure.
[root@localhost ~]# mysql -uroot -proot123
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 9
Server version: 5.6.47 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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@localhost ~]# mysql -uroot -proot123
查看当前数据库的字符集
mysql>show create database mysql;+----------+------------------------------------------------------------------+
| Database | Create Database |
+----------+------------------------------------------------------------------+
| mysql | CREATE DATABASE `mysql` /*!40100 DEFAULT CHARACTER SET latin1*/ |
+----------+------------------------------------------------------------------+
1 row in set (0.00 sec)
查看当前数据库版本
[root@localhost ~]# mysql -uroot -p123 -e "use mysql;select version();"mysql: [Warning] Using a password on the command line interface can be insecure.+-----------+
| version() |
+-----------+
| 5.7.29 |
+-----------+[root@localhost~]# mysql -V
mysql Ver14.14 Distrib 5.7.29, for Linux (x86_64) using EditLine wrapper
查看当前登录用户
[root@localhost ~]# mysql -uroot -p123 -e "select user();"mysql: [Warning] Using a password on the command line interface can be insecure.+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
select user(); #进入数据库查询
创建GBK字符集数据库mingongge并查看完整创建语句
mysql>create database mingongge default charset gbk collate gbk_chinese_ci;
Query OK,1 row affected (0.00 sec)
创建用户mingongge使用之可以管理数据库mingongge
mysql> grant all on mingongge.* to 'mingongge'@'localhost' identified by 'mingongge'
->;
Query OK,0 rows affected, 1 warning (0.20 sec)
查看创建用户mingongge的权限
mysql> show grants formingongge@localhost;+------------------------------------------------------------------+
| Grants for mingongge@localhost |
+------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'mingongge'@'localhost' |
| GRANT ALL PRIVILEGES ON `mingongge`.* TO 'mingongge'@'localhost' |
+------------------------------------------------------------------+
2 rows in set (0.00 sec)
查看当前数据库有哪此用户
mysql> selectuser from mysql.user;+---------------+
| user |
+---------------+
| mingongge |
| mysql.session |
| mysql.sys |
| root |
+---------------+
4 rows in set (0.01 sec)
进入mingongge数据库
mysql>use mingongge
Database changed
创建一个innodb GBK表test,字段id int(4)和name varchar(16)
mysql>create table test (-> d int(4),-> name varchar(16)-> )ENGINE=innodb DEFAULT CHARSET=gbk;
Query OK,0 rows affected (0.30 sec)
查看建表结构及表结构的SQL语句
mysql>desc test;+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| d | int(4) | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.05sec)
mysql>show create table test\G*************************** 1. row ***************************Table: test
Create Table: CREATE TABLE `test` (
`d`int(4) DEFAULT NULL,
`name` varchar(16) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=gbk1 row in set (0.00 sec)
插入一条数据“1,mingongge”
mysql> insert into test values('1','mingongge');
Query OK,1 row affected (0.01 sec)
再批量插入2行数据“2,ljj”,“3,mingonggeedu”
mysql> insert into test values('2','ljj'),('3','mingonggeedu');
Query OK,2 rows affected (0.00sec)
Records:2 Duplicates: 0 Warnings: 0
查询名字为mingongge的记录
mysql> select * from test where name = 'mingongge';+------+-----------+
| d | name |
+------+-----------+
| 1 | mingongge |
+------+-----------+
1 row in set (0.05 sec)
把数据id等于1的名字mingongge更改为mgg
mysql> update test set name = 'mgg' where d = '1';
Query OK,1 row affected (0.00sec)
Rows matched:1 Changed: 1 Warnings: 0
在字段name前插入age字段,类型tinyint(2)
mysql> alter table test add age tinyint(2) after d;
Query OK,0 rows affected (0.17sec)
Records:0 Duplicates: 0 Warnings: 0mysql>desc test->;+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| d | int(4) | YES | | NULL | |
| age | tinyint(2) | YES | | NULL | |
| name | varchar(16) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
不退出数据库,完成备份mingongge数据库
mysql> system mysqldump -uroot -p123 -B mingongge >/root/mingongge_bak.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@localhost~]# ls mingongge_bak.sql -l-rw-r--r-- 1 root root 2044 1月 15 10:57 mingongge_bak.sql
MySQL和Linux试题_Linux运维必会的MySql题之(一)相关推荐
- 运维之道 | Linux运维必会的MySQL企业面试题
Linux运维必会的MySQL企业面试题 基础笔试命令 1.开启MySQL服务 [root@localhost ~]# /etc/init.d/mysqld start [root@localhost ...
- php调取 zabbix实时数据_Linux运维必知的Zabbix故障排错实战
从0开始解决线上Zabbix监控平台故障 (1)学习Linux技术,后期从事Linux运维方面的工作,作为运维人员最主要的工作职责之一:保障企业门户网站.业务系统.数据库.服务器高效稳定的运行,一旦有 ...
- 面试题mysql环境搭建_Linux运维必会的100道MySql面试题之(四)
020:如何开启从库的binlog功能? 修改配置文件加上下面的配置 log_bin=slave-bin log_bin_index=slave-bin.index 需要重启服务 021:MySQL如 ...
- mysql 建表语句 及完整案例_Linux运维必会的100道MySql面试题之(一)
01 如何启动MySql服务 /etc/init.d/mysqld start service mysqld start Centos 7.x 系统 sysctl start mysqld02 检测端 ...
- 运维mysql数据库面试题_运维面试题之数据库
mysql篇: mysql主从复制原理? mysql的复制是基于3个线程 1.master上的binlog dump线程负责把binlog 事件传到slave 2.slave上面的IO线程负责接收bi ...
- linux运维必学python吗_linux运维一定要学python吗?
基于Python本身的优点:简单,易学,速度快,免费.开源,高层语言,可移植性,解释性,可扩展性,可嵌入性,丰富的库,独特的语法.Python已经成为现在编程的必备语言.作为"胶水语言&qu ...
- 新开班全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程
新开班全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程 全栈Linux运维的课程意义,在于让同学们从Liunx基础课程开始,一路直通Liunx运维高级架构师的级别.全新 ...
- 全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程
全栈Linux运维-Linux云计算运维与高级架构班课程 全新自动化运维必学课程 全栈Linux运维的课程意义,在于让同学们从Liunx基础课程开始,一路直通Liunx运维高级架构师的级别.全新的Li ...
- 【转载】运维角度浅谈MySQL数据库优化
运维角度浅谈MySQL数据库优化 2015-06-02 14:22:02 标签:mysql优化 mysql分库分表分区 mysql读写分离 mysql主从复制 原创作品,允许转载,转载时请务必以 ...
最新文章
- 追根究底之追本溯源:光标
- RTOS之uCOS-II源码下载及源码目录结构、常见的RTOS!
- PAT甲级1088 Rational Arithmetic:[C++题解]分数的加减乘除
- PaaS服务之路漫谈(一)
- maven项目打包插件:将maven项目打包成一个可执行的jar(瘦jar)
- node服务器放vue项目,本地Vue项目跨域请求本地Node.js服务器的配置方法
- Laravel 5 4 实现前后台登录
- Luogu P4168 [Violet]蒲公英 分块
- 手机python文本编辑器下载_python写的一个文本编辑器
- 解构流存储 — Pravega,与 Flink 构建端到端的大数据流水处理线
- [编程语言]C陷阱与缺陷
- 逆radon变换matlab,Radon变换及其Matlab代码实现
- oracle表空间加密
- OSChina 周二乱弹 —— 怎么让可爱的女孩子吃药
- python调用打印机打印图片
- 程序员 键盘 符号 字符 单词
- JS:变量提升与临时性死区TDZ
- 服务器监控之ping监控
- 多城市二手车买卖发布管理小程序开发
- 新标准下企业申请测绘资质相关问题与解答
热门文章
- Sublime Text 4首个稳定版发布:全新UI、多选项卡、支持GPU渲染
- 皮一皮:20岁和30岁的你的区别...
- 每日一皮:一个项目开发的真实写照...
- 每日一皮:据说这是很多公司的办事流程
- 如何监控impala的数据_CDH秘籍(两):cloudera Manager存储监控数据
- python and or 优先级
- C2059 语法错误:“)”
- pip install 另一个程序正在使用此文件,进程无法访问
- variables needed for gradient computation has been modified by an inplace operation
- python opencv多边形掩膜