MySQL simple configuration in Linux

Source: Internet
Author: User

MySQL simple configuration in Linux

1. Start the MySQL service command:

[[Email protected] ~]# service musqld start

2. Log in to the database, the default user name is root, no password. After entering MySQL, press the ENTER key to operate the database directly:

[[email protected] ~]# MySQL

Mysql>

3. Set the root password:

[Email protected] ~]# mysqladmin-u root password "pwd"

4. Log in to the database using a password:

[Email protected] ~]# mysql-u root-ppwd

Mysql>

5. Set the encoding format for the database to Utf-8:

  --View MySQL's default encoding:

Mysql>show variables like ' character% '

+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | Latin1 |
| character_set_connection | Latin1 |
| Character_set_database | Latin1 |
| Character_set_filesystem | binary |
| Character_set_results | Latin1 |
| Character_set_server | Latin1 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+ 

-- Modify the main configuration file/etc/my.cnf file for MySQL. (If there is no my.cnf file under the/etc/directory, need to find/usr/share/mysql/file under *.cnf, copy one to/etc/ and renamed to MY.CNF). The command is as follows:

[Email protected] ~]# cp/usr/share/mysql/my-medium.cnf/etc/my.cnf Note: Copy *.cnf file to/etc/and rename to My.cnf

  -- Edit the My.cnf file and add the red code as shown below

[Email protected] ~]# VI/ETC/MY.CNF

[Client]
  Default-character-set=utf8

[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
User=mysql
Lower_case_table_names=1
# Disabling Symbolic-links is recommended to prevent assorted security risks
Symbolic-links=0
  Character-set-server=utf8
init_connect= ' SET NAMES UTF8 '

[MySQL]
No-auto-rehash
  Default-character-set=utf8

[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid

  --Exit Edit command: Press ESC, enter: number, and then enter X to save and exit. The encoding format of the database is set up.

  --Restart MySQL service:

  [Email protected] ~]# service mysqld restart

  [Email protected] ~]# mysql-u root-ppwd

Mysql>show variables like ' character% '

+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+

< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >6. Create User:

< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" > mysql>  insert into Mysql.user (Host,user,password) VALUES (' localhost ', ' name ', Password (' pwd '));

< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" ><  Span class= "Apple-converted-space" > mysql> flush privileges;  Note: Refresh permissions

< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >7. Create database with library name dbname:

< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" ><  Span class= "Apple-converted-space" > mysql> CREATE database dbname;

< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" >8. Assign all permissions for the operation database dbname to the name User:

< Span class= "Apple-converted-space" >< Span class= "Apple-converted-space" ><  Span class= "Apple-converted-space" > Mysql> grant all privileges in dbname.* to name@ '% '  identified by ' pwd ';   

mysql> flush privileges;

mysql>\q          note: Exit MySQL

9. Log in to MySQL with Root, delete other users:

mysql> DELETE from user WHERE user= ' name ' and  host= ' localhost '; Note: Delete user

mysql> drop Database dbname; NOTE: Deleting a database

10. Open the 3306 port of MySQL so that the remote machine can access it.

  -- first determine if the host for the remote user is%, if not, log in to MySQL with Root and set host to%

mysql> Update Mysql.user Set host = '% ' where user = ' name ';

Mysql> Select Host, user from Mysql.user;

  --Open the firewall file and add the following red line:

  [Email protected] ~]# Vi/etc/sysconfig/iptables

# Firewall configuration written by System-config-firewall
# Manual Customization of this file are not recommended.
*filter
: INPUT ACCEPT [0:0]
: FORWARD ACCEPT [0:0]
: OUTPUT ACCEPT [0:0]
-A input-m state--state established,related-j ACCEPT
-A input-p icmp-j ACCEPT
-A input-i lo-j ACCEPT
-A input-m state--state new-m tcp-p TCP--dport 22-j ACCEPT
  -A input-m state--state new-m tcp-p TCP--dport 3306-j ACCEPT
-A input-j REJECT--reject-with icmp-host-prohibited
-A forward-j REJECT--reject-with icmp-host-prohibited
COMMIT

  --Restart the firewall:

[Email protected] ~]# service iptables restart

MySQL simple configuration in Linux

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.