Alibaba Cloud Centos7.3 install and configure Mysql

The first step: get mysql YUM source

Go to the mysql official website to get the RPM package download address

https://dev.mysql.com/downloads/repo/yum/

Insert picture description here
click to download
Insert picture description here

Right-click to copy the link address https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Get this, this is the rpm package of Yum warehouse is actually a download address

Step 2: Download and install mysql source

First download the mysql source installation package

[root@localhost ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

-bash: wget: command not found

Let's install wget first

yum -y install wget

Then execute wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Install mysql source

yum -y localinstall mysql57-community-release-el7-11.noarch.rpm

Step 3: Install Mysql online

yum -y install mysql-community-server

You need to wait a little while downloading a lot of things.

Step 4: Start the Mysql service

systemctl start mysqld

Step 5: Set boot up

[root@localhost ~]# systemctl enable mysqld

[root@localhost ~]# systemctl daemon-reload

Step 6: Modify root local login password

After the mysql installation is complete, a temporary default password is generated for root in the /var/log/mysqld.log file.

[root@localhost ~]# vi /var/log/mysqld.log

The temporary password here is eMV.R#mWe3ha
Insert picture description here
[root@localhost ~]# mysql -u root -p

Enter password:

Enter the temporary password to enter the mysql command line;

mysql> ALTER USER ‘root’@‘localhost’ IDENTIFIED BY ‘ZhipengWang2012@’;

Query OK, 0 rows affected (0.00 sec)

Change the password to ZhipengWang2012@ (Note that the default password policy of mysql5.7 requires that the password must be a combination of uppercase and lowercase alphanumeric special letters, at least 8 digits)
1QAZ2wsx!@

Step 7: Set to allow remote login

Mysql does not allow remote login by default, we need to set it, and the firewall opens port 3306;

mysql> GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ IDENTIFIED BY ‘1QAZ2wsx!@’ WITH GRANT OPTION;

Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> exit;

Bye

Exit

[root@localhost ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

[root@localhost ~]# firewall-cmd --reload

success

[root@localhost ~]#

Open port 3306

Step 8: Configure the default encoding as utf8 and host binding

Modify the /etc/my.cnf configuration file and add the encoding configuration under [mysqld], as shown below:

[mysqld]
character_set_server=utf8
init_connect=‘SET NAMES utf8’
bind-address = 0.0.0.0

[root@localhost ~]# vi /etc/my.cnf

After editing and saving, restart the mysql service;

[root@localhost ~]# systemctl restart mysqld

[root@localhost ~]#

Check the code:

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/ |

±-------------------------±---------------------------+

8 rows in set (0.00 sec)

Step 9: Navicat connection

Navicat connect to mysql appeared 2003-can't connect to mysql server on localhost

Change Alibaba Cloud Server = "Network and Security =" Add a security group
Open the 3306 port of mysql, and open up the ports that may be used by the way

Continue to link, still unsuccessful.
Server details = "Security =" firewall and manually add ports such as mysql3306 that need to be opened

The connection is successful and the Mysql installation and configuration is complete;

Common mysql operations

1 View the mysql version

Method 1: status;
Method 2: select version();

2 Mysql start, stop, restart common commands
a, start method

	1 使用 service 启动:
	[root@localhost /]# service mysqld start (5.0版本是mysqld)
	[root@szxdb etc]# service mysql start (5.5.7版本是mysql)
		
	2 使用 mysqld 脚本启动:
	/etc/inint.d/mysqld start
	
	3 使用 safe_mysqld 启动:
	safe_mysqld&

b, stop

1、使用 service 启动:
service mysqld stop

2、使用 mysqld 脚本启动:
/etc/inint.d/mysqld stop

3、mysqladmin shutdown

c, restart

1、使用 service 启动:
service mysqld restart 
service mysql restart (5.5.7版本命令)

2、使用 mysqld 脚本启动:
/etc/init.d/mysqld restart

Two, connect to MySQL:

格式: mysql -h主机地址 -u用户名 -p用户密码

1、例1:连接到本机上的MYSQL

找到mysql的安装目录,一般可以直接键入命令mysql -uroot -p,回车后提示你输密码,如果刚安装好MYSQL,超级用户root是没有密码的,故直接回车即可进入到MYSQL中了,MYSQL的提示符是:mysql>

2、连接到远程主机上的MySQL

假设远程主机的IP为:10.0.0.1,用户名为root,密码为123。则键入以下命令:

mysql -h10.0.0.1 -uroot -p123

(注:u与root可以不用加空格,其它也一样)

3、退出MySQL命令

exit (回车)

Guess you like

Origin blog.csdn.net/dandan2810/article/details/113360433