Mysql数据库和Linux系统常用命令分享
只得开始手工清除垃圾文件的漫长之路,正好也借这个机会把Mysql好好规整一下,删除过期不用的数据库、回收闲置的帐户权限,力争安全稳定可靠
Linux服务器瘫痪了3天,居然又是Mysql调皮捣蛋,让IDC重启服务器后发现Mysql启动失败,反复重启机器和Mysql均无效,顿时心口发凉,真 是世风日下、民不聊生、暗无天日啊,刚回北京就不让我消停。可算找到原因了,居然是Mysql莫名其妙多了一些超大文件,160G的硬盘空间被占用的满满 的,根本已经跑不动,这服务器已发生了太多离奇之事,我已见怪不怪、坦然处之。
只得开始手工清除垃圾文件的漫长之路,正好也借这个机会把Mysql好好规整一下,删除过期不用的数据库、回收闲置的帐户权限,,力争安全稳定可靠持久的运行 下去。这个动作还不小,由于phpmyadmin下没有发现 PHP 的扩展设置mbstring, 当前系统好像在使用宽字符集。没有 mbstring 扩展的 phpMyAdmin 不能正确识别字符串,结果phpmyadmin无法对数据库帐户进行管理,只得使用命令行来解决这个问题;这就需要了解一些Mysql常用的命令,比如: 显示/打开数据库、应用表、显示表字段以及基本的添加/删除/更新字段的命令,我整理了下分享给大家:
1:使用SHOW语句找出在服务器上当前存在什么数据库:
mysql> SHOW DATABASES;
2:创建一个数据库MYSQLDATA
mysql> CREATE DATABASE MYSQLDATA;
3:选择你所创建的数据库
mysql> USE MYSQLDATA; (按回车键出现Database changed 时说明操作成功!)
4:查看现在的数据库中存在什么表
mysql> SHOW TABLES;
5:创建一个数据库表
mysql> CREATE TABLE MYTABLE (name VARCHAR(20), sex CHAR(1));
6:显示表的结构:
mysql> DESCRIBE MYTABLE;
7:往表中加入记录
mysql> insert into MYTABLE values ("hyq","M");
8:用文本方式将数据装入数据库表中(例如D:/mysql.txt)
mysql> LOAD DATA LOCAL INFILE "D:/mysql.txt" INTO TABLE MYTABLE;
9:导入.sql文件命令(例如D:/mysql.sql)
mysql> use database;
mysql> source d:/mysql.sql;
10:删除表
mysql> drop TABLE MYTABLE;
11:清空表
mysql> delete from MYTABLE;
12:更新表中数据
mysql> update MYTABLE set sex="f" where name=hyq;
此外,Linux下经常使用的命令:
1:导入数据库备份文件的方法:
root: mysql –u数据库帐户 –p密码 数据库名 2:MySql的用户管理是通过User表来实现的,添加新用户常用的方法有两个,一是在User表插入相应的数据行,同时设置相应的权限;二是通过GRANT命令创建具有某种权限的用户。其中GRANT的常用用法如下:
mysql> grant all privileges on 用户名.* to 数据库名@localhost identified by “密码”;
3:清空文件内容:
cat /dev/null > 文件名
4:添加帐户:
useradd 用户名 –d 目录名 –s /sbin/nologin(不允许该用户直接登录服务器)
5:设置帐户密码
passwd 用户名
特别注意:
刚安装好的MySql包含一个含空密码的root帐户和一个匿名帐户,这是很大的安全隐患,对于一些重要的应用我们应将安全性尽可能提高,在这里应把匿名帐户删除、 root帐户设置密码,可用如下命令进行:
use mysql;
delete from User where User="";
update User set Password=PASSWORD(newpassword) where User=root;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL index cardinality has a significant impact on query performance: 1. High cardinality index can more effectively narrow the data range and improve query efficiency; 2. Low cardinality index may lead to full table scanning and reduce query performance; 3. In joint index, high cardinality sequences should be placed in front to optimize query.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.
