Under Ali cloud Mysql under Linux installation and configuration records on Mysql installation and configuration Ali cloud linux

Record the installation and configuration on Ali cloud Mysql linux

Environment: ECS Ali cloud server, the system is centos7.2

User: root

Reference blog: https://blog.csdn.net/kunzai6/article/details/81938613 brothers ha ha ha, also spoke in great detail of new users and set permissions

     https://blog.csdn.net/qq_39005790/article/details/80017186

 

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   // check out mariadb installed 
[root @ localhost ~] # rpm -e --nodeps file name   // unload mariadb, check out the file named above command file

 

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

Finally, there will be a complete!

4. Start MySQL service

[root@localhost ~]# systemctl start  mysqld.service

See something like the interface, or to Starting MySqL server .. started MysqlServer .. ending successfully launched

 

There are several commonly used commands on MySQL:

Restart: systemctl restart mysqld.service 

stop: systemctl stop mysqld.service 

view status: systemctl status mysqld.service

 

You can also configure the MySQL boot:

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

[root @ woitumi- 128 ~] # systemctl-daemon reload the configuration of the service just need to be able to identify systemctl, you must refresh configuration

 

 

 

 Log on MySQL:

Login command:

[root@localhost ~]# mysql -u root -p

Meaning that log in as root user, then prepare to enter a password.

After the first start MySQL, there will be a temporary password, the default initial password /var/log/mysqld.log file, we can use this command to view:

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

But I do not know if the wrong password or can not copy and paste, has been an error:

 

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

 

Then we can skip password authentication to log into MySQL:

Out of service:

systemctl stop mysqld.service

MMySQL modify configuration files:

we /etc/my.cnf

Add the final configuration:

skip-grant-tables

And then start the service:

systemctl start mysqld.service

 

Then then you can skip the password to log mysql:

mysql -u root

 

Then the modifications Password: (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

 

然后exit退出mysql,重新在刚刚那个配置文件中去掉skip-grant-tables,然后重启MySQL。

 

然后就可以用新密码登录了:

 

sql报错

但这个时候,我试了一下一个简单的sql语句:

 

what???我不是刚刚才设完密码吗??

然后百度了下。说这个情况还要加个这样的改密码的语句:

SET PASSWORD = PASSWORD('密码');

但这个命令又出现了这样的问题:

额百度后知道原来是密码等级太简单,如果你坚持要这样的密码,要改变密码等级:

登录数据库后,输入

mysql> set global validate_password_policy=0;  //改变密码等级 mysql> set global validate_password_length=4; //改变密码最小长度

然后再输入刚刚的命令:

SET PASSWORD = PASSWORD('密码');

然后再用 show databases;就没有报错了

 

 

配置远程登录:

MySQL默认root用户只能本地登录,如果要远程连接,要简单设置下,这里直接用root来远程登录不添加其他角色。

使用命令:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '4008' WITH GRANT OPTION;

.*.的意思是所有库的所有表;To后面跟的是用户名;@后面跟的是ip地址,%代表所有ip地址,identified by后面的是密码。

然后再:

mysql> flush privileges;

 

注意:

需要注意mysql的配置文件中的bindaddress 的参数和skip-networking 配置

bindaddress : 设定哪些ip地址被配置,使得mysql服务器只回应哪些ip地址的请求),最好注释掉该参数或设置成为127.0.0.1以外的值

skip-networking : 如果设置了该参数项,将导致所有TCP/IP端口没有被监听,也就是说出了本机,其他客户端都无法用网络连接到本mysql服务器,所以应该注释掉该参数

 

 

添加3306端口:

命令:

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

 

结果说没有运行防火墙:

 

那就先开防火墙咯:

systemctl status firewalld  查看防火墙状态

systemctl start firewalld  打开防火墙

 

 

 

然后再输入那个开放3306端口的命令就行了

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

firewall-cmd --reload  重启防火墙

 

 

 

 

最后的收尾:

1.我们刚开始说要写在yum的repository,用这个命令就行:

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

 

2.MySQL设一下utf8:

打开/etc/my.cnf也就是数据库的配置文件,然后在底部复制粘贴:

[mysqld] 

character_set_server=utf8 init_connect='SET NAMES utf8'

采用navicat新建数据库时,需要将编码方式设置为,字符集:utf8 -- UTF-8 Unicode ,排序规则:utf8_general_ci

3.阿里云的服务器中的安全组加入mysql连接的规则。这个很重要不然远程无法连接上。

4.配置文件的说明:

  /etc/my.cnf 这是mysql的主配置文件
  /var/lib/mysql mysql数据库的数据库文件存放位置
  /var/log mysql数据库的日志输出存放位置

 

本文转载自:https://www.cnblogs.com/wangshen31/p/9556804.html

Guess you like

Origin www.cnblogs.com/zydeboke/p/11467095.html