After installing mysql, configure the environment variables and then
Input mysql
Go to mysql
Then you can
Use mysql;
Select * from user;
To view all users;
Execute the script file in Mysql:
Mysql> source xxx. SQL;
1.1 add users in two ways: (convert)
There are two different ways to add users: using the GRANT statement or directly operating the MySQL authorization table. The better way is to use the GRANT statement, because they are more concise and seem to have fewer errors.
The following example shows how to use a MySQL client to install a new user. These examples assume that the permission has been installed by default. This means that, in order to change, you must be on the same machine that MySQL is running, you must be connected as the MySQL root user, and the root user must have the insert permission and reload management permission on the MySQL database. In addition, if you change the root user password, you must specify it using the following MySQL command.
You can add new users by issuing the GRANT statement:
Shell> mysql -- user = root mysql
Mysql> grant all privileges on *. * TO monty @ localhost
Identified by 'something' with grant option;
Mysql> grant all privileges on *. * TO monty @ "%"
Identified by 'something' with grant option;
Mysql> grant reload, process on *. * TO admin @ localhost;
Mysql> grant usage on *. * TO dummy @ localhost;
These GRANT statements install three new users:
Monty: A full super user who can connect to the server from anywhere, but must use a password ('something' to do this. Note: You must issue a GRANT statement to monty @ localhost and monty @ "%. If we add a localhost entry, the entry created by mysql_install_db for the anonymous user entry of localhost takes priority when we connect from the local Host, because it has a more specific Host field value, therefore, the user table is arranged in the order of users.
Admin: a user who can connect from localhost without a password and is granted reload and process management permissions. This allows you to run the mysqladmin reload, mysqladmin refresh, mysqladmin flush-* commands, and mysqladmin processlist commands. No database-related permissions are granted. They can GRANT permissions in the future by issuing another GRANT statement.
Dummy: you can connect to a user without a password, but only from the local host. The global permission is set to 'n' -- the USAGE permission type allows you to set a user without permission. It assumes that you will grant database-related permissions in the future.
You can also directly add the same user access information by issuing an INSERT statement, and then tell the server to load the authorization table again:
Shell> mysql -- user = root mysql
Mysql> insert into user VALUES ('localhost', 'monty ', PASSWORD ('something '),
'Y ', 'y', 'y ')
Mysql> insert into user VALUES ('%', 'monty ', PASSWORD ('something '),
'Y ', 'y', 'y ')
Mysql> insert into user SET Host = 'localhost', User = 'admin ',
Reload_priv = 'y', Process_priv = 'y ';
Mysql> insert into user (Host, User, Password)
VALUES ('localhost', 'dummy ','');
Mysql> flush privileges;
Depending on your MySQL version, for the above, you may have to use a different number of 'y' values (versions earlier than 3.22.11 have fewer permission columns ). For admin users, only the INSERT extension syntax that is more readable in version 3.22.11.
Note: To set a Super user, you only need to create a user table entry with the permission field set to 'y '. No db or host table entries are required.
The permission columns in the user table are not explicitly set by the last INSERT statement (for dummy users), so those columns are assigned the default value 'n '. This is the same thing grant usage does.
In the following example, add a User custom, which can be connected from the host localhost, server. domain, and whitehouse.gov. He only wants to access the bankaccount database from localhost, the expenses database from whitehouse.gov, and the customer database from all three hosts. He wants to use the password stupid from all three hosts.
To use the GRANT statement to set permissions for individual users, run these commands:
Shell> mysql -- user = root mysql
Mysql> grant select, INSERT, UPDATE, DELETE, CREATE, DROP
ON bankaccount .*
TO custom @ localhost
Identified by 'stupid ';
Mysql> grant select, INSERT, UPDATE, DELETE, CREATE, DROP
ON expenses .*
TO custom@whitehouse.gov
Identified by 'stupid ';
Mysql> grant select, INSERT, UPDATE, DELETE, CREATE, DROP
ON customer .*
TO custom @ '%'
Identified by 'stupid ';
Run these commands by directly modifying the authorization table to set user permissions (Note: flush privileges at the end ):
Shell> mysql -- user = root mysql
Mysql> insert into user (Host, User, Password)
VALUES ('localhost', 'custom', PASSWORD ('stupid '));
Mysql> insert into user (Host, User, Password)
VALUES ('server. domain ', 'custom', PASSWORD ('stupid '));
Mysql> insert into user (Host, User, Password)
VALUES ('whitehouse. gov ', 'custom', PASSWORD ('stupid '));
Mysql> insert into db
(Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
Create_priv, Drop_priv)
VALUES
('Localhost', 'bankaccount', 'custom', 'y ');
Mysql> insert into db
(Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
Create_priv, Drop_priv)
VALUES
('Whitehouse. gov ', 'expenses', 'custom', 'y ');
Mysql> insert into db
(Host, Db, User, Select_priv, Insert_priv, Update_priv, Delete_priv,
Create_priv, Drop_priv)
VALUES ('%', 'customer', 'custom', 'y', 'y ');
Mysql> flush privileges;
The first three INSERT statements Add user table entries, allowing custom to connect from different hosts with a given password, but no permission is granted (all permissions are set to the default value 'n '). Add db table entries in the last three INSERT statements, and grant custom database permissions to the bankaccount, expenses, and customer databases. However, the database can only be accessed from the correct host. Generally, when the authorization table is directly modified, the server must be notified to mount them again (use flush privileges) to make the permission modification take effect.
If you want to give a specific user access to any machine in a given domain, you can issue the following GRANT statement:
Mysql> GRANT...
ON *.*
TO myusername @ "% .mydomainname.com"
Identified by 'mypassword ';
To do the same thing by directly modifying the authorization table:
Mysql> insert into user VALUES ('% .mydomainname.com', 'myusername ',
PASSWORD ('mypassword '),...);
Mysql> flush privileges;
You can also use xmysqladmin, mysql_webadmin, or even xmysql to insert, change, and update values in the authorization table. You can find these utilities in the Contrib directory of MySQL. (T004)
1.2 What should I do if I forget my password?
1. First kill the mysqld process:
Kill-TERM mysqld
2. Use the skip-grant-tables option to start MySQL:
/Usr/bin/mysqld_safe-skip-grant-tables
3. log on to change the password:
# Mysql-u root-p
Mysql> use mysql;
Mysql> update user set password = password ('new _ pass') where user = 'root ';
Mysql> flush privileges;
Mysql> exit;
4. Turn off MySQL
# Mysqladmin-u root-p shutdown
5. Start MySQL
/User/bin/mysqld_safe-user = mysql &
2. How does Mysql Import and Export databases?
(Reproduced in http://hi.baidu.com/chenshengang/blog/item/644f7a16c49016064a90a7ab.html)
How to import and export a MySQL database
Release: | Author: Jianxin transparent | Source: local site Forum | view: 111 times
There are two ways to import a MySQL database:
1) Export the database SQL script first and then import it;
2) directly copy database directories and files.
In different operating systems or MySQL versions, the method of directly copying files may be incompatible.
Therefore, we recommend that you use SQL scripts to import data. The following describes two methods.
2. Method 1: SQL script
The procedure is as follows:
2.1. Export an SQL script
On the original database server, you can use the phpMyAdmin tool or the mysqldump command (the mysqldump command is located in the mysql/bin/directory) command line to export the SQL script.
2.1.1 phpMyAdmin
Select "structure" and "data" to export. Do not add the "Drop DATABASE" and "Drop TABLE" options.
Select the "Save As file" option. If there is more data, select the "gzipped" option.
Save the exported SQL file.
2.1.2 use mysqldump command line
Command Format
Mysqldump-u username-p Database Name> database name. SQL
Example:
Mysqldump-uroot-p abc> abc. SQL
(Export the database abc to the abc. SQL file)
Enter the password of the Database User Name When prompted.
2.2. Create an empty Database
Create a database on the master page/control panel. Assume that the database name is abc and the database full user is abc_f.
2.3. Import and execute SQL scripts
You can use either phpMyAdmin or mysql command line.
2.3.1 use phpMyAdmin
From the control panel, select the created empty database and click "manage" to go to the management tools page.
In the "SQL" menu, browse and select the exported SQL file, and click "run" to load and execute the file.
Note: phpMyAdmin has a limit on the size of the uploaded file, and php itself has a limit on the size of the uploaded file. If the original SQL File
Relatively large, you can use gzip to compress it. For text files such as SQL files, you can obtain a compression rate of or higher.
Gzip usage:
# Gzip xxxxx. SQL
Get
Xxxxx. SQL .gz file.
2.3.2 use mysql Command Line
Command Format
Mysql-u username-p database name <database name. SQL
Example:
Mysql-uabc_f-p abc <abc. SQL
(Import database abc from abc. SQL file)
Enter the password of the Database User Name When prompted.
3 method 2 Direct Copy
If the database is large, you can use the direct copy method. However, different versions and operating systems may be incompatible with each other, so use it with caution.
3.1 prepare the original file
Package A file with tar
3.2 Create an empty Database
3.3 decompress
Decompress the package in the temporary directory, for example:
Cd/tmp
Tar zxf mydb.tar.gz
3.4 copy
Copy the extracted database file to the relevant directory.
Cd mydb/
Cp */var/lib/mysql/mydb/
For FreeBSD:
Cp */var/db/mysql/mydb/
3.5 permission settings
Change the owner of the copied files to mysql: mysql and the permission to 660.
Chown mysql: mysql/var/lib/mysql/mydb /*
Chmod 660/var/lib/mysql/mydb /*
3. Use of oracle in linux
A really abnormal company. It's really troublesome to use oracle + mysql for a project, but you still have to learn
Installing oracle in Linux is troublesome, but it is very important to check the environment in the early stage. You should install oracle as required.
Is used
Sqlplus/nolog
Connect xxx/xxx as sysdba;
Startup
./Dbca is a visual interface for creating databases.
Start/snrctl
./Netca -- start listener
Execute script files in Oracle
Sqlplus> @ xxx. SQL