Ali cloud Mysql linux installation and configuration

Installation and Configuration Mysql recorded on Ali cloud linux
environment:阿里云ECS服务器,系统为centos7.2

User: root

Delete the original database:

centos7 installed by default in the database MariaDB, MySQL If you install it, will be covered directly out of the database, of course, you can delete it manually:

[root@localhost ~]# rpm -qa|grep mariadb  // 查询出来已安装的mariadb
[root@localhost ~]# rpm -e --nodeps 文件名  // 卸载mariadb,文件名为上述命令查询出来的文件

And now the current directory to the root is: cd ~

Download and install MySQL:

Well, here using a variety of Yum dependent rpm package management, can automatically download the RPM packages from the specified server and installed, it must be relieved after installation, otherwise it will be automatically updated.

1. Install the MySQL official yum repository

[root@localhost ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

2. Download the rpm package

[root@localhost ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm

3. Install the MySQL service

[root@localhost ~]# yum -y install mysql-community-server
最后会出现个complete!

4. Start MySQL service

[root@localhost ~]# systemctl start  mysqld.service
看到类似下面的界面,或者以Starting MySqL server..   started MysqlServer..结尾的就成功启动了

There are several commonly used commands on MySQL:

重启:systemctl restart mysqld.service

停止:systemctl stop mysqld.service

查看状态:systemctl status mysqld.service
 

You can also configure the MySQL boot:

[root@woitumi-128 ~]# systemctl enable mysqld

[root@woitumi-128 ~]# systemctl daemon-reload   刚刚配置的服务需要让systemctl能识别,就必须刷新配置

Log on MySQL:

Login command:

[root@localhost ~]# mysql -u root -p
意思就是用root用户登录,然后准备输入密码。

第一次启动MySQL后,就会有临时密码,这个默认的初始密码在/var/log/mysqld.log文件中,我们可以用这个命令来查看:

grep "password" /var/log/mysqld.log


可是不知道是我输错密码还是不能复制粘贴,一直显示错误:

(Well, look at the back of this code should be mysql -u root -pfishes, may enter this command would be no mistake about it ......)

Then we 还可以先跳过密码验证登录进MySQL:

停止服务:

systemctl stop mysqld.service
修改mMySQL的配置文件:

vi /etc/my.cnf
在最后加上配置:

skip-grant-tables
然后再启动服务:

systemctl start mysqld.service
 

Then then you can skip the password to log mysql:

mysql -u root

然后是修改下密码:(See the example of others like this)

mysql> use mysql;
Database changed
mysql> update mysql.user set authentication_string=password('4008') where user='root' ;
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1
 

Then exit to exit mysql, again at just the profile to remove skip-grant-tables, and then restart MySQL.

Then you can log in with the new password:

sql error

But this time, I tried a simple sql statement:

what? ? ? I do not have just finished setting your password? ?

Then the next Baidu. He said the situation also add this statement to change the password:

SET PASSWORD = PASSWORD('密码');
但这个命令又出现了这样的问题:

After the amount of Baidu know that the password level is too simple, if you insist on such a password to change the password level:

登录数据库后,输入

mysql> set global validate_password_policy=0;  //改变密码等级

mysql> set global validate_password_length=4;   //改变密码最小长度
然后再输入刚刚的命令:

SET PASSWORD = PASSWORD('密码');
然后再用 show databases;就没有报错了

Configure remote login:

The default MySQL root user can log on locally, if you want to remotely connect to simple settings, remote login here directly without the addition of other roles with the root.

使用命令:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '4008' WITH GRANT OPTION;
.*.的意思是所有库的所有表;To后面跟的是用户名;@后面跟的是ip地址,%代表所有ip地址,identified by后面的是密码。

然后再:

mysql> flush privileges;
 

note:

bindaddress parameters and skip-networking to note mysql configuration file configuration

bindaddress: Which ip address setting is configured, so that what mysql server request only the response ip address), commented that the best parameter set, or a value other than 127.0.0.1

skip-networking: If you set this parameter entries will result in all TCP / IP port is not being monitored, that is a native, other clients are unable to connect to this network with mysql server, so you should comment out the parameter

添加3306端口:

命令:

firewall-cmd --zone=public --add-port=3306/tcp --permanent;
 

It said the results are not running a firewall:

First opened slightly firewall:

systemctl status firewalld  查看防火墙状态

systemctl start firewalld  打开防火墙
 

Then enter the command to open port 3306 on the line

firewall-cmd --zone=public --add-port=3306/tcp --permanent;

firewall-cmd --reload  重启防火墙
 

 

Final finishing:

1. We have just started to write in to say yum-repository, use this command line:

yum -y remove mysql57-community-release-el7-10.noarch
 

2.MySQL set about utf8:

/Etc/my.cnf is open profile database, and then copy and paste the bottom:


[mysqld] 

character_set_server=utf8
init_connect='SET NAMES utf8'

When using navicat new database, encoding needs to be set, the character set: utf8 - UTF-8 Unicode, collation: utf8_general_ci

3. Ali cloud server security group added rules mysql connection. This is heavy or else unable to connect on the remote.

4. DESCRIPTION profile:

/etc/my.cnf 这是mysql的主配置文件
  /var/lib/mysql mysql数据库的数据库文件存放位置
  /var/log mysql数据库的日志输出存放位置
Published 126 original articles · won praise 57 · views 90000 +

Guess you like

Origin blog.csdn.net/wolfGuiDao/article/details/104873039