一、安装 到MySQL官网上http://dev.mysql.com/downloads/mysql/,下载mysql可安装dmg版本 比如: Mac OS X ver. 10.7 (x86, 64-bit), DMG Archive 下载完的文件为:mysql-5.6.10-osx10.7-x86_64.dmg 1.点击,安装包里的 2.点击安装 安装好后,再系统偏好设置
一、安装
到MySQL官网上http://dev.mysql.com/downloads/mysql/,下载mysql可安装dmg版本
比如:Mac OS X ver. 10.7 (x86, 64-bit), DMG Archive
下载完的文件为:mysql-5.6.10-osx10.7-x86_64.dmg
1.点击,安装包里的
2.点击安装
安装好后,再系统偏好设置的其他里,会出现如下图标:
3.点击此图标,跳出对话框
点击Start MySQL Server按钮,启动mysql
二、打开终端,定义mysql别名
输入alias命令
alias mysql=/usr/local/mysql/bin/mysql
回车,再输入
alias mysqladmin=/usr/local/mysql/bin/mysqladmin
三、设置mysql root帐号的密码
mysqladmin -u root password 初始密码
2.如果设置完密码后,需要修改,执行命令
mysqladmin -u root -p password 最新密码
接着会提示输入密码,此时输入旧密码,回车
四、连接数据库
mysql -u root -p
然后提示输入密码,输入三中设置的初始密码
2.如果登陆远程主机上的mysql数据库
mysql -h 主机地址 -u 用户名 -p 用户密码
五、执行常用的mysql数据库操作
注意:以下操作都发现在,连接数据库之后,进入mysql环境,之后执行的命令都必须带有分号“;”
首先,以root权限连接mysql
mysql -u root -p
然后,输入root的密码
1、增加新用户
格式如下:
grant 操作权限 on 数据库.* to 用户名@登陆主机地址 identified by <span>'</span><span>密码</span><span>';</span>
意思是:授予,某主机上的某用户(附带该用户的登陆密码)在某数据库上,执行某些操作的权限
(1)比如:任意主机上("%"),用户(用户名:test1,密码:adc)在所有数据库上,执行任意操作的权限(很危险)
grant all privileges on *.* to test1<span>@"</span><span>%</span><span>"</span> identified by <span>"</span><span>abc</span><span>"</span>;
其中all privileges表示查询,插入,修改,删除的权限:select,insert,update,delete
以上命令等价于:
grant <span>select</span>,insert,update,delete on *.* to test1<span>@"</span><span>%</span><span>"</span> identified by <span>"</span><span>abc</span><span>"</span>;
然后刷新权限
flush privileges;
(2)比如:授权本地主机上的用户操作数据库的权限
创建数据库(比如:openfire)
create database openfire;
授予本地主机用户(用户名:test2,密码:123)访问数据库(数据库名称:openfire)的操作权限
grant all privileges on openfire.* to test2@localhost identified by <span>"</span><span>123</span><span>"</span>;
flush privileges;
之后,就可以用新的用户,访问openfire数据库了
2.更新指定帐户的密码(用户名:test1,新密码:1234)
update mysql.user set password=password(<span>'</span><span>1234</span><span>'</span>) where User=<span>"</span><span>test1</span><span>"</span> and Host=<span>"</span><span>localhost</span><span>"</span>;
3.删除用户
先使用mysql数据库
use mysql;
删除mysql数据库中user表中的某个本地用户(test7)
delete from user where User=<span>"</span><span>test7</span><span>"</span> and Host=<span>"</span><span>localhost</span><span>"</span>;
4.显示命令
(1)显示所有数据库列表
show databases;
初始化只有两个数据库,mysql和test
注意:MYSQL的系统信息都存储在mysql库中,比如:修改密码和新增用户,实际上就是用这个库进行操作
(2)打开某个数据库(比如数据库:openfire)
use openfire;
(3)显示本库中的所有表
show tables;
(4)显示某表(table1)的结构
describe table1;
(5)建库
create database 库名;
(6)建表
<span>use 库名; create table 表名 (字段设定列表);</span>
(7)删库
drop database 库名;
(8)删表
drop table 表名;
(9)将表中的记录清空
delete from 表名;
(10)显示表中的记录
<span>select</span> * from 表名;
六、退出mysql
exit
七、启动和停止MySQL
启动
/usr/local/mysql/share/mysql.server start
停止
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
输入root密码

MySQL'sBLOBissuitableforstoringbinarydatawithinarelationaldatabase,whileNoSQLoptionslikeMongoDB,Redis,andCassandraofferflexible,scalablesolutionsforunstructureddata.BLOBissimplerbutcanslowdownperformancewithlargedata;NoSQLprovidesbetterscalabilityand

ToaddauserinMySQL,use:CREATEUSER'username'@'host'IDENTIFIEDBY'password';Here'showtodoitsecurely:1)Choosethehostcarefullytocontrolaccess.2)SetresourcelimitswithoptionslikeMAX_QUERIES_PER_HOUR.3)Usestrong,uniquepasswords.4)EnforceSSL/TLSconnectionswith

ToavoidcommonmistakeswithstringdatatypesinMySQL,understandstringtypenuances,choosetherighttype,andmanageencodingandcollationsettingseffectively.1)UseCHARforfixed-lengthstrings,VARCHARforvariable-length,andTEXT/BLOBforlargerdata.2)Setcorrectcharacters

MySQloffersechar, Varchar, text, Anddenumforstringdata.usecharforfixed-Lengthstrings, VarcharerForvariable-Length, text forlarger text, AndenumforenforcingdataAntegritywithaetofvalues.

Optimizing MySQLBLOB requests can be done through the following strategies: 1. Reduce the frequency of BLOB query, use independent requests or delay loading; 2. Select the appropriate BLOB type (such as TINYBLOB); 3. Separate the BLOB data into separate tables; 4. Compress the BLOB data at the application layer; 5. Index the BLOB metadata. These methods can effectively improve performance by combining monitoring, caching and data sharding in actual applications.

Mastering the method of adding MySQL users is crucial for database administrators and developers because it ensures the security and access control of the database. 1) Create a new user using the CREATEUSER command, 2) Assign permissions through the GRANT command, 3) Use FLUSHPRIVILEGES to ensure permissions take effect, 4) Regularly audit and clean user accounts to maintain performance and security.

ChooseCHARforfixed-lengthdata,VARCHARforvariable-lengthdata,andTEXTforlargetextfields.1)CHARisefficientforconsistent-lengthdatalikecodes.2)VARCHARsuitsvariable-lengthdatalikenames,balancingflexibilityandperformance.3)TEXTisidealforlargetextslikeartic

Best practices for handling string data types and indexes in MySQL include: 1) Selecting the appropriate string type, such as CHAR for fixed length, VARCHAR for variable length, and TEXT for large text; 2) Be cautious in indexing, avoid over-indexing, and create indexes for common queries; 3) Use prefix indexes and full-text indexes to optimize long string searches; 4) Regularly monitor and optimize indexes to keep indexes small and efficient. Through these methods, we can balance read and write performance and improve database efficiency.


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

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Dreamweaver CS6
Visual web development tools

Atom editor mac version download
The most popular open source editor
