MYSQL教程:数据库具体操作_MySQL
1. 连接数据库服务器
$ ./mysql -h host_name -u user_name -p
-h host_name(--host=host_name),连接的数据库主机名,如果在本地主机上则可省略。
-u user_name(--user=user_name),数据库用户名,在unix系统上,如果系统的登录名与数据用户名一样,则可省略。在windows系统中,可通过设置环境变量USER来给出数据库用户名,如set USER=username。
-p(--password),提供数据库用户密码,有该选项mysql就会提示你输入密码。输入的密码以星号显示,以确保安全。也可直接在-p后写上密码(-p和密码间不能有空格),但这不安全,不推荐。
连接成功后,mysql数据库服务器会显示一些欢迎信息。接着就可用mysql>use database_name命令打开指定的数据库。
本文由网页教学网整理发布!转载请注明出处,谢谢!
$ ./mysql -h host_name -u user_name -p database_name命令可直接打开指定数据库。
2. 更新用户密码
mysql>update user set password=passowrd('your passowrd') where host='%';
刷新权限设置:mysql>flush privileges;
3. MySQL读取配置文件的顺序
my.cnf是MySQL数据库的配置文件,它存在多个地方,在/etc目录,数据目录和用户主目录都有。放在不同位置,里面的选项有不同的作用范围,下面是MySQL读取配置文件的顺序和作用。
mysql 读取配置文件的顺序:
/etc/my.cnf Global options.
DATADIR/my.cnf Server-specific options.
defaults-extra-file The file specified with the --defaults-extra-file option.
~/.my.cnf User-specific options.
4. 重设置MySQL管理员密码的方法
有时我们会因为设置原因或时间长了忘记了数据库管理员的密码,使得我们被关在MySQL服务器外。MySQL服务器提供了一种方法可使我们在服务器上重设密码。在windows和linux/unix平台上操作稍有不同,下面分别介绍:
Linux/Unix平台下:
用 % kill -TERM PID关闭服务器,用-TERM信息可使服务器在关闭前把内存中的数据写入磁盘。如果服务器没有响应,我们可用% kill -9 PID来强制删除进程,但不建议这样做。这时内存中的数据不会写入磁盘,造成数据不完整。如果你是用mysql_safe脚本启动MySQL服务器的,这个脚本会监控服务器的运行情况并在它被终止时重启服务器,所以如需关闭服务器,要先终止该进程,然后再真正终止mysqld进程。
使用--skip-grant-tables参数启动MySQL Server,这时MySQL服务器将不使用权限表对连接操作进行验证。你就可在不提供root密码的情况下连接上服务器,并获得root的权限。
% mysqld_safe --skip-grant-tables &
用以下命令登录服务器,并重设密码:
% mysql -u root
#不用密码就可连接到服务器
mysql> use mysql
mysql> set password for 'root'@'localhost' = password('password');
修改MySQL服务器帐户密码有三种方式,你可参考本笔记中数据库日常管理一章中的相关内容。在这种环境下,使用mysaladmin修改密码好象不行,还是提示要输入密码。
关闭服务器,再用正常方式启动服务器。
windows平台下:
用管理员帐号登录服务器,关闭MySQL数据库服务器。

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



With the rapid development of social media, Xiaohongshu has become one of the most popular social platforms. Users can create a Xiaohongshu account to show their personal identity and communicate and interact with other users. If you need to find a user’s Xiaohongshu number, you can follow these simple steps. 1. How to use Xiaohongshu account to find users? 1. Open the Xiaohongshu APP, click the "Discover" button in the lower right corner, and then select the "Notes" option. 2. In the note list, find the note posted by the user you want to find. Click to enter the note details page. 3. On the note details page, click the "Follow" button below the user's avatar to enter the user's personal homepage. 4. In the upper right corner of the user's personal homepage, click the three-dot button and select "Personal Information"

The Local Users and Groups utility is built into Computer Management and can be accessed from the console or independently. However, some users find that local users and groups are missing in Windows 11. For some people who have access to it, the message suggests that this snap-in may not work with this version of Windows 10. To manage user accounts for this computer, use the User Accounts tool in Control Panel. The issue has been reported in previous iterations of Windows 10 and is usually caused by issues or oversights on the user's side. Why are local users and groups missing in Windows 11? You are running Windows Home edition, local users and groups are available on Professional edition and above. Activity

In Ubuntu systems, the root user is usually disabled. To activate the root user, you can use the passwd command to set a password and then use the su- command to log in as root. The root user is a user with unrestricted system administrative rights. He has permissions to access and modify files, user management, software installation and removal, and system configuration changes. There are obvious differences between the root user and ordinary users. The root user has the highest authority and broader control rights in the system. The root user can execute important system commands and edit system files, which ordinary users cannot do. In this guide, I'll explore the Ubuntu root user, how to log in as root, and how it differs from a normal user. Notice

Certain folders are not always accessible due to permissions, and in today’s guide we will show you how to access user folders on your old hard drive on Windows 11. The process is simple but can take a while, sometimes even hours, depending on the size of the drive, so be extra patient and follow the instructions in this guide closely. Why can't I access my user folders on my old hard drive? User folders are owned by another computer, so you cannot modify them. You don't have any permissions on the folder other than ownership. How to open user files on old hard drive? 1. Take ownership of the folder and change permissions Find the old user directory, right-click on it and select Properties. Navigate to "An

Many users have been added to the Ubuntu system. I want to delete the users that are no longer in use. How to delete them? Let’s take a look at the detailed tutorial below. 1. Open the terminal command line and use the userdel command to delete the specified user. Be sure to add the sudo permission command, as shown in the figure below. 2. When deleting, be sure to be in the administrator directory. Ordinary users do not have this permission. , as shown in the figure below 3. After the delete command is executed, how to judge whether it has been truly deleted? Next we use the cat command to open the passwd file, as shown in the figure below 4. We see that the deleted user information is no longer in the passwd file, which proves that the user has been deleted, as shown in the figure below 5. Then we enter the home file

sudo (superuser execution) is a key command in Linux and Unix systems that allows ordinary users to run specific commands with root privileges. The function of sudo is mainly reflected in the following aspects: Providing permission control: sudo achieves strict control over system resources and sensitive operations by authorizing users to temporarily obtain superuser permissions. Ordinary users can only obtain temporary privileges through sudo when needed, and do not need to log in as superuser all the time. Improved security: By using sudo, you can avoid using the root account during routine operations. Using the root account for all operations may lead to unexpected system damage, as any mistaken or careless operation will have full permissions. and

Microsoft began rolling out KB2 to the public as an optional update for Windows 503145511H22 or later. This is the first update to enable Windows 11 Moment 4 features by default, including Windows Copilot in supported areas, preview support for items in the Start menu, ungrouping of the taskbar, and more. Additionally, it fixes several Windows 11 bugs, including potential performance issues that caused memory leaks. But ironically, the optional update for September 2023 will be a disaster for users trying to install the update, or even for those who have already installed it. Many users will not install this Wi

According to news from this site on July 23, Lenovo’s YOGA Portal high-performance desktop computer, which has been exposed for a long time, is now confirmed to be officially released at ChinaJoy in Shanghai on July 27. It is claimed to be a mini host designed for professional AI creation. It is a performance master and an expert in AI creation of 3D digital people. The AI virtual background is based on the on-site pictures provided by our friend @yuP in Shanghai. The volume of this small host is only 3.7L. It is made of anodized aluminum and is equipped with Intel Core. i7-14700 processor, equipped with 32GBDDR5 memory and 1TB solid state drive. YOGA Portal is both a host and an all-in-one AI creation machine. The high-performance host is combined with an algorithm-optimized camera to form an integrated solution. Just stand in front of the camera i.e.
