Install MySQL under redhat6.4 using CentOS's Yum source

Source: Internet
Author: User
Tags gpg mysql client

Idea: Uninstall Redhat with yum, then download the CentOS yum, install and modify the configuration file

1 , first to Http://mirrors.163.com/centos Download Package

x86 Address: http://mirrors.163.com/centos/6/os/i386/Packages/

x86_64 Address: http://mirrors.163.com/centos/6/os/x86_64/Packages/

The necessary packages to download are (for example, 64-bit systems):

A python-iniparse-0.3.1-2.1.el6.noarch.rpm

b yum-3.2.29-40.el6.centos.noarch.rpm

C yum-metadata-parser-1.1.2-16.el6.x86_64.rpm

D yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm

Download command:

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-40.el6.centos.noarch.rpm

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm

[Note]: The version does not have to be up-to-date, if the 404 file cannot be found, you can view the version number by http://mirrors.163.com/centos/6/os/x86_64/Packages/and fine-tune

2 , uninstall RedHat Bring your own Yum

Rpm-qa | grep Yum | Xargs rpm-e--nodeps

Note: A, xargs is a common command for UNIX and UNIX-like operating systems. It does this by converting the argument list to small pieces to pass to other commands to avoid the problem of too long argument lists

b 、--nodeps forced unloading, regardless of dependencies

3 , install the downloaded CentOS of the Yum Package:

RPM-IVH python-iniparse-0.3.1-2.1.el6.noarch.rpm

RPM-IVH yum-metadata-parser-1.1.2-16.el6.x86_64.rpm

RPM-IVH yum-3.2.29-40.el6.centos.noarch.rpm yum-plugin-fastestmirror-1.1.30-14.el6.noarch.rpm

[note]: The last 2 need to be installed together, or there will be a dependency error

4 , to http://mirrors.163.com of the CentOS Help Documentation Download in Centos6-base-163.repo files, stored in /ETC/YUM.REPO.D in

wget Http://mirrors.163.com/.help/CentOS6-Base-163.repo

5 , edit Centos6-base-163.repo file that will be one of the $releasever Change to CentOS the version number

Here are the modifications:

# Centos-base.repo

#

# The Mirror system uses the connecting IP address of the client and the

# Update status of each mirror to pick mirrors that is updated to and

# Geographically close to the client. You should the use of this for CentOS updates

# Unless you is manually picking other mirrors.

#

# If The mirrorlist= does not work for you, as a fall back to you can try the

# remarked out Baseurl= line instead.

#

#

[Base]

Name=centos-6-base-163.com

baseurl=http://mirrors.163.com/centos/6/os/$basearch/

#mirrorlist =http://mirrorlist.centos.org/?release=6&arch= $basearch &repo=os

Gpgcheck=1

Gpgkey=http://mirror.centos.org/centos/rpm-gpg-key-centos-6

#released Updates

[Updates]

Name=centos-6-updates-163.com

baseurl=http://mirrors.163.com/centos/6/updates/$basearch/

#mirrorlist =http://mirrorlist.centos.org/?release=6&arch= $basearch &repo=updates

Gpgcheck=1

Gpgkey=http://mirror.centos.org/centos/rpm-gpg-key-centos-6

#additional packages that could be useful

[Extras]

Name=centos-6-extras-163.com

baseurl=http://mirrors.163.com/centos/6/extras/$basearch/

#mirrorlist =http://mirrorlist.centos.org/?release=6&arch= $basearch &repo=extras

Gpgcheck=1

Gpgkey=http://mirror.centos.org/centos/rpm-gpg-key-centos-6

#additional packages that extend functionality of existing packages

[Centosplus]

Name=centos-6-plus-163.com

baseurl=http://mirrors.163.com/centos/6/centosplus/$basearch/

#mirrorlist =http://mirrorlist.centos.org/?release=6&arch= $basearch &repo=centosplus

Gpgcheck=1

Enabled=0

Gpgkey=http://mirror.centos.org/centos/rpm-gpg-key-centos-6

#contrib-packages by Centos Users

[Contrib]

Name=centos-6-contrib-163.com

baseurl=http://mirrors.163.com/centos/6/contrib/$basearch/

#mirrorlist =http://mirrorlist.centos.org/?release=6&arch= $basearch &repo=contrib

Gpgcheck=1

Enabled=0

Gpgkey=http://mirror.centos.org/centos/rpm-gpg-key-centos-6

6 , Yum Clean All Clear Old Cache

7 , Yum Makecache Get Yum List

The following prompt indicates that the Yum change is complete:

Metadata Cache Created

8 , Yum install MySQL

Install MySQL.

[Root@sample ~]# yum-y install mysql-server← installing MySQL
[Root@sample ~]# yum-y install php-mysql← installation Php-mysql

Configure MySQL

[Root@sample ~] #vim/etc/my.cnf← Edit the 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 = utf8← Add this line

Then add the following statement at the end of the configuration file:

[MySQL]
Default-character-set = UTF8

Start the MySQL service

[Root@sample ~]# chkconfig mysqld on← set up MySQL service with system boot from boot

[Root@sample ~]# 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

Initializing MySQL database: [OK]
Starting MySQL: [OK]
MySQL Initial environment setting

[1] Setting a password for the root user of MySQL

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

Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 2 to server version:4.1.20

Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.

Mysql>grant all on mysql.* to ' root ' @ ' localhost ' identified by ' password ';
You can then log in to MySQL via a password.

Set up MySQL to allow extranet access

1. Modify the configuration file
sudo vim/etc/mysql/my.cnf
Change the value of the bind-address parameter to your internal/external network IP or 0.0.0.0, or comment out the line directly.


2. Log in to the database
Mysql-u root-p

Enter password
mysql> use MySQL;


3. Querying the Host
Mysql> select User,host from user;


4. Create host
If there is no "%" of this host value, the following two sentences are executed:
mysql> Update user set host= '% ' where user= ' root ';
mysql> flush Privileges;


5. Authorized Users
Any host connected to the MySQL server with user root and password mypwd
Mysql> GRANT All privileges on * * to ' root ' @ '% ' identified by ' mypwd ' with GRANT OPTION;
mysql> flush Privileges;

Hosts with IP 192.168.1.102 connect to MySQL server with user myuser and password mypwd
Mysql> GRANT All privileges on * * to ' myuser ' @ ' 192.168.1.102 ' identified by ' mypwd ' with GRANT OPTION;
mysql> flush Privileges;

MySQL new user, authorization, delete user, change password


1. CREATE USER

Grammar:

CREATE USER ' username ' @ ' host ' identified by ' password ';

Example: CREATE USER ' dog ' @ ' localhost ' identified by ' 123456 ';

CREATE USER ' pig ' @ ' 192.168.1.101_ ' idendified by ' 123456 ';

CREATE USER ' pig ' @ '% ' identified by ' 123456 ';

CREATE USER ' pig ' @ '% ' identified by ';

CREATE USER ' pig ' @ '% ';

Example 1:

mysql> Create user JSS;

This creates a user who can create a connection from any machine that has a MySQL client installed and has access to the target server, without the need for a password. For example, to perform a connection from a ip:10.0.0.99 client:

Mysql-ujss-h 172.16.1.110

View the User:

Mysql> Select User,host,password from user where user= ' JSS ';

SELECT USER (); Show Current User

Example 2:

Mysql> create user Jss_ps identified by ' JSS ';

When a user connects, a password must be specified, and the password can be set by specifying the identified by clause when the user is created

Login with Password:

Mysql-ujss_ps-p-H 172.16.1.110

If you want the specified user to be accessible only from one of the specified domains or hosts, you can specify host when you create the user, for example, specify that the user can access only from 10.0.0.99

mysql> create user [email protected] identified by password ' 123456 ';

2. Using the GRANT statement

Syntax:mysql> grant permission 1, permission 2,... Permission n on the database name. Table name to User name @ user address identified by ' connection password ';

Permissions 1, Permissions 2,... Permission N represents

14 privileges such as Select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file

Instance:

Mysql>grant Select,insert,update,delete,create,drop on Vtdc.employee to [e-mail protected] identified by ' 123 ';

Assign the user Joe from 10.163.225.87 the ability to perform operations such as Select,insert,update,delete,create,drop on the employee table VTDC the database, and set the password to 123.

Mysql>grant all privileges in vtdc.* to [e-mail protected] identified by ' 123 ';

For users from 10.163.225.87, Joe assigns permissions to all operations on the database VTDC all tables, and sets the password to 123.

Mysql>grant all privileges on * * to [e-mail protected] identified by ' 123 ';

For users from 10.163.225.87, Joe assigns permissions to all the tables in all databases and sets the password to 123.

Mysql>grant all privileges on * * to [e-mail protected] identified by ' 123 ';

Assign the native user Joe permission to all operations on all tables in all databases, and set the password to 123.

3. Insert the record directly into the Mysql.user table:

mysql> INSERT INTO User (Host,user,password) values ('% ', ' Jss_insert ', password (' JSS '));

Mysql>flush privileges; Refresh System Permissions Table

4. Modify the MySQL user password method:

A. Using mysqladmin syntax: mysqladmin-u user Name----old password password new password

For example: mysqladmin-u root-p 123 password 456;

B. Directly modify the user password for the users table:

Syntax: Update mysql.user set Password=password (' New password ') where user= "Phplamp" and host= "localhost";

Example: Update user set Password=password (' 54netseek ') where user= ' root ';

Flush privileges;

C. Use the Set Password statement to modify the password: syntax:

SET PASSWORD for ' username ' @ ' host ' = PASSWORD (' NewPassword ');

If it is the current login user with Set PASSWORD = PASSWORD ("NewPassword");

Instance:

Set password for [email Protected]=password (');

SET PASSWORD for Name=password (' New PASSWORD ');

SET PASSWORD for ' pig ' @ '% ' = PASSWORD ("123456");

5. Delete users and Revoke permissions:

A. Cancelling an account and its permissions

Drop user User;

drop user [email protected] '% '

drop user [email protected]

B. Cancellation of authorized users:

Syntax: REVOKE privilege on databasename.tablename from ' username ' @ ' host ';

Example: REVOKE SELECT on * * from ' pig ' @ '% ';

REVOKE SELECT on Test.user from ' pig ' @ '% ';

Revoke all on * * from [email protected];

Revoke all on user.* from ' admin ' @ '% ';

SHOW GRANTS for ' pig ' @ '% '; View authorizations

C. Delete users:

Syntax: Delete from user where user = "user_name" and host = "HOST_NAME";

Example: Delete from user where user= ' sss ' and host= ' localhost ';

Second, the database table

1. View all databases: Database directory:/usr/local/mysql/data

Mysql> SHOW DATABASES; Display Database

mysql> use ABCCS//Enter database

Mysql> SHOW TABLES; Show Table

Mysql> DESCRIBE mytable; Show Table Structure

mysql> CREATE DATABASE Abccs; Create a database

Mysql> CREATE TABLE mytable (name VARCHAR), sex CHAR (1), birth DATE, Birthaddr VARCHAR (20)); Create a table

mysql> INSERT INTO mytable values (' Abccs ', ' f ', ' 1977-07-07 ', ' China '); inserting table Data

Insert Data Using text:

{

Mysql.txt content: Abccs F 1977-07-07 China

Mary F 1978-12-12 USA

Tom M 1970-09-02 USA

mysql> LOAD DATA LOCAL INFILE "Mytable.txt" into TABLE pet; Import TXT file data

}

2. Delete the database:

mysql> drop Database drop_database; Delete a database that has been determined to exist

ALTER TABLE name engine= storage engine name;//modify Tables Storage engine

ALTER TABLE name drop attribute name;//delete field

ALTER TABLE old table name rename to new table name;//Modify table name

ALTER TABLE name modify property name data type;//modify field data type

ALTER TABLE name change old property name new data type of new property name;//Modify field name

ALTER TABLE name drop foreing key foreign key alias;//delete child table FOREIGN KEY constraint

Add Table field:

{ALTER TABLE example add phone Vacgar (20);//Add unconstrained fields

ALTER TABLE example add Age INT (4) is not NULL; Fields that increase the constraint

ALTER TABLE example add num INT (8) PRIMARY KEY first; Increment field at the first position of a table

ALTER TABLE example add address VARCHAR (+) not NULL after phone; Adds a field after the specified position in the table

ALTER TABLE example modify name VARCHAR (a) first; Change the field to the first bit

ALTER TABLE example Modify NUM INT (8) Ater phone;//after the field has been modified to the specified field

}


Install MySQL under redhat6.4 using CentOS's Yum source

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.