Linux MySQL Database setup

Source: Internet
Author: User
Tags name database

Set the shared package address 192.168.80.10

Setenforce 0

Service Iptables Stop

1. Sharing Packages

Mount.cifs//192.168.80.10/r/media/Anonymous access to shared folders

cd/media/

LS to see if the mount is successful

Tar xzvf mysql-5.5.24.tar.gz-c/opt/extract to/opt/

cd/opt/mysql-5.5.24

Mount/dec/cdrom/mnt

Yum Install cmake-y installation CMake

Useradd mysql-s/sbin/nologin Add can log in to MySQL user, but cannot log on to the system

Mkdir-p/usr/local/mysql

Perform Yum install-y ncurses-devel to see if this package is installed

Execute the following script:

CMake \

-DCMAKE_INSTALL_PREFIX=/USR/LOCAL/MYSQL \ Installation Path

-dmysql_datadir=/home/mysql/\ Data File

-dmysql_unix_addr=/home/mysql/mysql.sock \

-dwith_myisam_storage_engine=1 \

-dwith_innobase_storage_engine=1 \

-dwith_archive_storage_engine=1 \

-dwith_blackhole_storage_engine=1 \

-denabled_local_infile=1 \

-ddefault_charset=utf8 \

-DDEFAULT_COLLATION=UTF8_GENERAL_CI \

-dextra_charsets=all \

-dwith_ssl=system \

-dmysql_tcp_port=3306 \

-denable_downloads=1 \

-dwith_ssl=bundled

(Note: If the Yum install-y ncurses-devel command is not executed before installation, there may be an error.)

At this point, execute the previous command to resolve the issue, and execute RM CMakeCache.txt to delete the cache and then re-execute CMake)

If no error is taken, execute make

If no error is provided, execute make install

Chown-r mysql.mysql/usr/local/mysql Change the permissions of MySQL

Export path= $PATH:/usr/local/mysql/bin/ initializing environment variables

(Note that the initialization here is temporary, if you want to start from running, execute

VI ~/.bash_profile

Add a command

Path= $PATH:/usr/local/mysql/bin/)

CP support-files/my-medium.cnf/etc/my.cnf //Setup configuration file

CP Support-files/mysql.server/etc/init.d/mysqld

Add the system service, copy the Mysql.server script file to the/etc/init.d/directory, and rename it to Mysqld

chmod 755/etc/init.d/mysqld Setting Execution permissions

Chkconfig--add/etc/init.d/mysqld Add/ETC/INIT.D/MYSPLD to Chkconfig, manage with service command (service MySQL)

Chkconfig mysqld--level 235 on

Init script mysql_install_db is located in the Scripts folder of the installation directory

/usr/local/mysql/scripts/mysql_install_db \

--user=mysql \ Specify user as MySQL

--ldata=/var/lib/mysql \ Link file is/var/lib/mysql

--basedir=/usr/local/mysql \ Basic directory,/USR/LOCAL/MYSQ

--datadir=/home/mysql Data Directory is/home/mysql

Ln-s/var/lib/mysql/mysql.sock/home/mysql/mysql.sock

Vi/etc/init.d/mysqld

Modify the following two parameters:

Basedir=/usr/local/mysql

Datadir=/home/mysql

Save

Source/root/.bash_profile Loading configuration files immediately

At this point, all the configuration files have been modified,

Perform service mysqld start start services

NETSTAT-TNL | grep 3306 can check the running status of the 3306-port mysqld Service

2. Debug Mysqld

Mysql-u root//Login database


-------View Commands----------

mysql> show databases;


mysql> use test;


Mysql> Show tables;


mysql> describe user; View table contents (view the contents of the user table)


----------New command-----------

Mysql>create DATABASE Benet; //Create a database named Benet

Mysql>use Benet; Enter the Benet database


Mysql> CREATE TABLE Users (user_name CHAR (+) not NULL,

USER_PASSWD CHAR (+) DEFAULT ', PRIMARY KEY (user_name)); //

Create a table named users

----------------

Note: "User_name" represents the field 1 name (i.e. the first row of the table), "Char

(16) "representation type," not NULL "means null value cannot be null no;

"USER_PASSWD" means the field 2 names (i.e. the second

Line), "char (48)" represents the type, "default" means NULL can be null yes;

"PRIMARY KEY (user_name)" means primary key (primary key name)

-----------

Mysql> INSERT into Users (USER_NAME,USER_PASSWD) VALUES

(' Zhangsan ', PASSWORD (' 123456 ')); Inserting content in the users table

Mysql> INSERT into Users VALUES (' Lisi ', PASSWORD (' 654321 '));

Password is password-encrypted by the user

Mysql> INSERT into users values (' Sina ', password (' 123abc '));


------------Delete command--------------

Mysql> DELETE from users WHERE user_name= ' Lisi ';


mysql> DROP TABLE users;


mysql> DROP DATABASE Benet;


----------Change the command---------

mysql> UPDATE users SET User_passwd=password (") WHERE

User_name= ' Lisi ';

mysql> UPDATE mysql.user SET password=password (' 123456 ') WHERE

user= ' root ';


------------Query Command-----------

Mysql> SELECT User,host,password from Mysql.user WHERE

User= ";

Mysql> select * from users; View all information in the user table

Mysql> Select User from users; View the user word in the users table

Which users are in the paragraph

Mysql>flush privileges; Refresh authorization information,


mysqladmin-u root-p password ' 123456 '//change is a new password, to enter

Is the old password, executed in #.

Enter Password://Enter old password


[[email protected] ~]# mysql-u root-p //Login

Enter Password: //Enter the previously changed password 123456


---------------Authorization Commands-------------------

Mysql> GRANT Select on auth.* to ' Tom ' @ ' localhost ' identified

By ' 123456 ';//New Tom User password is set to 123456, its authorization can only be queried to

All tables beginning with Auth.


Mysql> Grant all on benet.* to ' Tom ' @ ' 192.168.80.4 ' identified

By ' 123 ';

Mysql>flush privileges;

GRANT statement: specifically used to set access rights for database users. When the specified user does not exist

, the GRANT statement will create a new user, otherwise Grnat

Statement user modifies user information. The statement format is as follows:

GRANT permission list on library name. Table name to ' user name ' @ ' source

"Identfied by ' password '"


mysql> SHOW GRANTS for ' dbuser ' @ ' 192.168.4.19 '; (for example, the example above

Sub: SHOW GRANTS for ' tom ' @ ' localhost ', that "username @ Source Address"

If the same)

Mysql> REVOKE all on auth.* from ' xiaoqi ' @ ' localhost ';


---------------Backup and Restore commands------------------


# mysqldump-u root-p--opt--all-databases > All-data.sql//

Back up all databases

# mysqldump-u root-p--database benet > Benet.sql//Backup Auth

Database

# mysqldump-u root-p Benet users > B-user.sql//Backup MySQL

User table


Mysql>create Benet;

#mysql-U root-p < benet.sql

# mysql-u Root-p MySQL < mysql-user.sql//restore Backup to MySQL

The database.


Example:

Mysqldump-u root-p--database user > User.sql//name in database

Back up the user's database (back up the user database)


Mysql-u root-p < Benet.sql//will back up the user database name database

User.sql restoring to the database




This article is from the "Ne Road" blog, please be sure to keep this source http://332162926.blog.51cto.com/8831013/1534956

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.