Install MySQL-related notes under Linux

Source: Internet
Author: User
Tags anonymous

Install MySQL
Yum-y Install Mysql-server
Yum-y install MySQL Mysql-devel

It's all going to be done.

View the MySQL version number
Rpm-qi Mysql-server

Database directory
/var/lib/mysql/
Configuration file
/usr/share/mysql (mysql.server command and configuration file)
Related commands
/usr/bin (Mysqladmin mysqldump and other commands)
Startup scripts
/etc/rc.d/init.d/(startup script file for MySQL directory)

Start MySQL:

Service mysqld Start

Stop MySQL:

Service Mysqld Stop

Change Password and configuration:

Yum installed MySQL By default there are two users one is an empty user is anonymous user, one is root but the password is also empty, this can not.

First, if you are using an anonymous user or logged in, you encounter this error:ignoring query to other database

Indicates that you did not add-u This parameter when you landed

Let's talk about how to configure it.

Second, the configuration
[[email protected] ~]# vi/etc/my.cnf← edit MySQL configuration file

[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
# Default to using old password format for compatibility with MySQL 3.x
# clients (those using the Mysqlclient10 compatibility package).
old_passwords=1← find this line, add a new rule below this line, let MySQL default code is UTF-8
Default-character-set = gbk← Add this line
Then add the following statement at the end of the configuration file:

[MySQL]
Default-character-set = GBK

Third, start the MySQL service

[[email protected] ~]# chkconfig mysqld on← set up MySQL service with system boot from boot

If the above command fails, show Bash:chkconfig:command not found, see the following workaround in this article

[[email protected] ~]# chkconfig--list mysqld← confirm MySQL self-booting
Mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off← If 2--5 is on the status OK

[[email protected] ~]#/etc/rc.d/init.d/mysqld start← start MySQL service

Start MySQL [OK]

Note: If this fails to execute, it is possible that/var/lib/mysql does not have a database file that will be reported "Fatal Error:can ' t open and Lock Privilege tables:table ' mysql.host ' doesn ' t Exist ", this is required to execute the mysql_install_db command on OK.

Four, the root user set the MySQL password
When MySQL was first installed, its root user was not set to the password. Start by setting up the root password for MySQL.

[[email protected] ~]# mysql-u root← Log in to the MySQL server with the root user

: If error occurs can ' t connect to local MySQL server through socket '/var/lib/mysql/mysql.sock ' (2),

: Check to see if MySQL is starting/etc/rc.d/init.d/mysqld status and/etc/rc.d/init.d/mysqld start without booting
Mysql> select User,host,password from Mysql.user; ← Viewing user Information
Mysql>set password for [email Protected]=password (' Enter root password here '); ← Set Root Password
Mysql>set password for [email protected] Domain name =password (' Enter root password here ');
Mysql> Delete from mysql.user where user= '; ← Deleting anonymous users
mysql> exit← exit MySQL server "Test setup password is correct"


V. Delete the test database
mysql> show databases; ← Viewing a database that already exists on the system
mysql> drop database test; ← Deleting an empty database named Test

Six, the MySQL test. This includes setting up new users and trying to build databases and data tables with instructions for database operations on relational databases. Here, the new user takes sleinetpub as an example.

[[email protected] ~]# mysql-u root-p← login with root by password
Enter password:← the password here

Mysql> grant all privileges in test.* to [email protected] identified by ' Define password here ';  ← Create a user named Sleinetpub that has full operation permissions on the test database
mysql> Select User from Mysql.user where user= ' sleinetpub '; ← Confirm the presence or absence of the sleinetpub user
Mysql> exit← exit the MySQL server
[[email protected] ~]# mysql-u sleinetpub-p← with the newly created Sleine  Tpub user logs on to MySQL server
Enter password:← Enter password here
mysql> CREATE DATABASE test;  ← Create a database named Test
mysql> Show databases;  ← View a database that already exists
Mysql> use test← connect to database
mysql> CREATE TABLE test (num int, name varchar (50));  ← Set up tables in the database
mysql> show tables;  ← View tables that already exist in the database
mysql> drop table test;  ← Delete Table
mysql> show databases; ← View Existing Database
Empty Set (0.01 sec) ← Confirm that the test database has been deleted (this is a non-root user relationship and cannot see a database named MySQL)
mysql> exit← exit MySQL server


Vii. Delete legacy users that have been tested
[[email protected] ~]# mysql-u root-p← login with root by password
Enter password:← the password here
Mysql> revoke all privileges on * * FROM [email protected]; ← Cancel sleinetpub User permissions on database operations
Mysql> Delete from Mysql.user where user= ' sleinetpub ' and host= ' localhost '; ← Delete sleinetpub Users
Mysql> Select User from Mysql.user where user= ' sleinetpub '; ← Find User sleinetpub, confirm deleted or not
Empty Set (0.01 sec) ← Confirm Sleinetpub User no longer exists
mysql> flush Privileges; ← Refresh to make the above actions effective
Mysql> exit

Eight, finally, restart the HTTP service.

[[email protected]/]#/etc/rc.d/init.d/mysqld stop← stop HTTP Service
Stop MySQL [OK]

[[email protected]/]#/etc/rc.d/init.d/mysqld start← start HTTP Service
Start MySQL [OK]

Install MySQL-related notes under Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.