MySQL学习笔记_MySQL
bitsCN.com
MYSQL数据库 如何 配置:
一般只要修改一下my.ini就行,把它指到数据库目录下
柳永法(yongfa365)Blog已测试最简单方法:
1. net stop mysql
2. 打开 C:Program FilesMySQLMySQL Server 5.1my.ini
编辑
datadir="C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/"
为
datadir="D:/Data/"
3. 移动"C:/Documents and Settings/All Users/Application Data/MySQL/MySQL Server 5.1/Data/"到别的地方,如:D:/Data/
4. net start mysql
这样做以后重装系统只要修改my.ini就可以了,数据库及相应权限都一下子恢复了。
=============================================
MYSQL数据库 简单提醒:
MYSQL 以 ; 表示输入结尾,这样才会执行,回车或go很多时候是没有用的。
MYSQL的管理工具柳永法(yongfa365)Blog感觉比较好的有:phpMyAdmin Navicat
=============================================
MYSQL数据库里 如何 建用户,分配权限:
bin>mysql -u root -p
Enter password: *********
mysql> grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by 连接口令;
权限1,权限2,…权限n代表select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file等14个权限。
当权限1,权限2,…权限n被all privileges或者all代替,表示赋予用户全部权限。
当数据库名称.表名称被*.*代替,表示赋予用户操作服务器上所有数据库所有表的权限。
用户地址可以是localhost,也可以是ip地址、机器名字、域名。也可以用%表示从任何地址连接。
连接口令不能为空,否则创建失败。
例如:
mysql>grant select,insert,update,delete,create,drop on dbname.employee to joe@10.163.225.87 identified by 123;
给来自10.163.225.87的用户joe分配可对数据库dbname的employee表进行select,insert,update,delete,create,drop等操作的权限,并设定口令为123。
mysql>grant all privileges on dbname.* to joe@10.163.225.87 identified by 123;
给来自10.163.225.87的用户joe分配可对数据库dbname所有表进行所有操作的权限,并设定口令为123。
mysql>grant all privileges on *.* to joe@10.163.225.87 identified by 123;
给来自10.163.225.87的用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
mysql>grant all privileges on *.* to joe@localhost identified by 123;
给本机用户joe分配可对所有数据库的所有表进行所有操作的权限,并设定口令为123。
=============================================
MYSQL数据库里 如何修改密码
首先要声明一点,大部分情况下,修改MySQL是需要有mysql里的root权限的,所以一般用户无法更改密码,除非请求管理员。
方法一
使用phpmyadmin,这是最简单的了,修改mysql库的user表,不过别忘了使用PASSWORD函数。
方法二
使用mysqladmin。
mysqladmin -u root -p password mypasswd
输入这个命令后,需要输入root的原密码,然后root的密码将改为mypasswd。
把命令里的root改为你的用户名,你就可以改你自己的密码了。
当然如果你的mysqladmin连接不上mysql server,或者你没有办法执行mysqladmin,那么这种方法就是无效的,而且mysqladmin无法把密码清空。
用mysqladmin来改密码的常见问题:
有好多人是这样修改的:
C:>mysqladmin -u root -p password yongfa365
Enter password: *********
Warning: single quotes were not trimmed from the password by your command line client, as you might have expected.
这个时候真正的新密码是yongfa365 而新手往往认为新密码是yongfa365如:
C:>mysql -u root -pyongfa365
ERROR 1045 (28000): Access denied for user root@localhost (using password: YES)
所以非常郁闷,BAIDU、GOOGLE的搜了一大堆。
我现在把密码改回去。
C:>mysqladmin -u root -pyongfa365 password 123456
下面的方法都在mysql提示符下使用,且必须有mysql的root权限:
方法三
mysql> Insert INTO mysql.user (Host,User,Password) VALUES (%,jeffrey,PASSWORD(biscuit));
mysql> FLUSH PRIVILEGES
确切地说这是在增加一个用户,用户名为jeffrey,密码为biscuit。
在《mysql中文参考手册》里有这个例子,所以我也就写出来了。
注意要使用PASSWORD函数,然后还要使用FLUSH PRIVILEGES。
方法四
和方法三一样,只是使用了REPLACE语句
mysql> REPLACE INTO mysql.user (Host,User,Password) VALUES (%,jeffrey,PASSWORD(biscuit));
mysql> FLUSH PRIVILEGES
方法五
使用SET PASSWORD语句,
mysql> SET PASSWORD FOR jeffrey@% = PASSWORD(biscuit);
拟也必须使用PASSWORD()函数,但是不需要使用FLUSH PRIVILEGES。
方法六
使用GRANT ... IDENTIFIED BY语句
mysql> GRANT USAGE ON *.* TO jeffrey@% IDENTIFIED BY biscuit;
这里PASSWORD()函数是不必要的,也不需要使用FLUSH PRIVILEGES。
=============================================
MYSQL数据库如何备份及恢复 备份MYSQL数据库 还原MYSQL数据库
备份数据目录下的 mysql 目录和你的数据库同名的目录
然后重新安装mysql以后,只要主版本一致(比如mysql 5.1和mysql 5.2,他们的主版本都是5)
安装以后,使用 net stop mysql 命令停止mysql服务(服务运行状态下你是无法备份及复制的)
然后删除新安装的mysql数据目录下的mysql文件夹,然后将你之前备份的复制到此即可。
这样恢复后,mysql用户信息及你的相关设置和原来的一样。
其实还有一个更简单的办法,我一般都是这么做:
修改my.ini的配置,将mysql的数据储存文件夹放置到指定的分区。即使需要重装系统,再次安装同一版本的mysql以后,再次修改my.ini将数据储存文件夹指回你的目录就行了。 方法如最上边的如何配置柳永法
=============================================
MYSQL数据库 常用命令
一、连接MYSQL。
格式: mysql -h 主机地址 -u 用户名 -p 用户密码
1、例1:连接到本机上的MYSQL。
首先在打开DOS窗口,然后进入目录 mysqlin,再键入命令mysql -u root -p,回车后提示你输密码,如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql>
2、例2:连接到远程主机上的MYSQL。假设远程主机的IP为:110.110.110.110,用户名为root,密码为yongfa365。则键入以下命令:
mysql -h 110.110.110.110 -u root -p yongfa365
(注:u与root可以不用加空格,其它也一样)
3、退出MYSQL命令: exit (回车)
二、修改密码。
格式:mysqladmin -u用户名 -p旧密码 password 新密码
1、例1:给root加个密码yongfa365。首先在DOS下进入目录mysqlbin,然后键入以下命令
mysqladmin -u root -password yongfa365
注:因为开始时root没有密码,所以-p旧密码一项就可以省略了。
2、例2:再将root的密码改为djg345。
mysqladmin -u root -p yongfa365 password djg345
三、增加新用户。(注意:和上面不同,下面的因为是MYSQL环境中的命令,所以后面都带一个分号作为命令结束符)
格式:grant select on 数据库.* to 用户名@登录主机 identified by 密码;
例1、增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。首先用以root用户连入MYSQL,然后键入以下命令:
grant select,insert,update,delete on *.* to test1@% Identified by abc;
但例1增加的用户是十分危险的,你想如某个人知道test1的密码,那么他就可以在internet上的任何一台电脑上登录你的mysql数据库并对你的数据可以为所欲为了,解决办法见例2。
例2、增加一个用户test2密码为abc,让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作(localhost指本地主机,即MYSQL数据库所在的那台主机),这样用户即使用知道test2的密码,他也无法从internet上直接访问数据库,只能通过MYSQL主机上的web页来访问了。
grant select,insert,update,delete on mydb.* to test2@localhost identified by abc;
如果你不想test2有密码,可以再打一个命令将密码消掉。
grant select,insert,update,delete on mydb.* to test2@localhost identified by ;
在上篇我们讲了登录、增加用户、密码更改等问题。下篇我们来看看MYSQL中有关数据库方面的操作。注意:你必须首先登录到MYSQL中,以下操作都是在MYSQL的提示符下进行的,而且每个命令以分号结束。
一、操作技巧
1、如果你打命令时,回车后 bitsCN.com

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

AI Hentai Generator
Generate AI Hentai for free.

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



Go language is an efficient, concise and easy-to-learn programming language. It is favored by developers because of its advantages in concurrent programming and network programming. In actual development, database operations are an indispensable part. This article will introduce how to use Go language to implement database addition, deletion, modification and query operations. In Go language, we usually use third-party libraries to operate databases, such as commonly used sql packages, gorm, etc. Here we take the sql package as an example to introduce how to implement the addition, deletion, modification and query operations of the database. Assume we are using a MySQL database.

Hibernate polymorphic mapping can map inherited classes to the database and provides the following mapping types: joined-subclass: Create a separate table for the subclass, including all columns of the parent class. table-per-class: Create a separate table for subclasses, containing only subclass-specific columns. union-subclass: similar to joined-subclass, but the parent class table unions all subclass columns.

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

HTML cannot read the database directly, but it can be achieved through JavaScript and AJAX. The steps include establishing a database connection, sending a query, processing the response, and updating the page. This article provides a practical example of using JavaScript, AJAX and PHP to read data from a MySQL database, showing how to dynamically display query results in an HTML page. This example uses XMLHttpRequest to establish a database connection, send a query and process the response, thereby filling data into page elements and realizing the function of HTML reading the database.

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

1. Make preparations. Import a piece of material into the material library and drag it to the timeline. 2. Click the [T] button on the timeline track, choose to add subtitles on the 1T track, and you will enter the subtitle editing page. The operation is as shown in the picture: 3. Here you can write the text content we want. It is obvious that the subtitles are written horizontally. Now let’s take a look at how to implement vertical subtitles. Don't write the content yet, select [Insert - Text - Vertical] as shown in the picture: 4. Now write the words and it will be arranged vertically. After adjusting the position, size, font, color and other information of the subtitles, click Save in the upper left corner of the window.

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

PHP is a back-end programming language widely used in website development. It has powerful database operation functions and is often used to interact with databases such as MySQL. However, due to the complexity of Chinese character encoding, problems often arise when dealing with Chinese garbled characters in the database. This article will introduce the skills and practices of PHP in handling Chinese garbled characters in databases, including common causes of garbled characters, solutions and specific code examples. Common reasons for garbled characters are incorrect database character set settings: the correct character set needs to be selected when creating the database, such as utf8 or u
