Linux (CentOs) install MySQL 5.6.5

Linux (CentOs) install MySQL 5.6.5

I am new, if you have any questions, please go to the bottom of the original text to ask questions.

This article reference: https://blog.csdn.net/KingWeiGG/article/details/107309012

1. Check if there are dependencies

rpm -qa | grep mariadb

2. Delete if there is mariadb

rpm -e (该处写mariadb按Tab键) --nodeps

3. Download MySQL Community Edition

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

若没有wget就先使用这个命令安装
yum install -y wget

4. Unzip

不管在哪个位置解压都行,系统会将文件解压到提前制定好的目录
rpm -ivh mysql-community-release-el7-5.noarch.rpm

5. Download the MySQL-server tool

yum install -y mysql-server

6. Authorize users to use MySQL

该处是直接对root用户授权了,有些教程是创建一个叫MySQL的linux用户,然后再对这个MySQL的用户分组授权
,个人觉得如果没有硬性要求,就对root用户授权就行了,不用了整的那么麻烦。

chown -R root:root /var/lib/mysql

7. Start the MySQL service

启动命令:
service mysql start

拓展:
查询MySQL状态:
service mysql status

停止MySQL服务:
service mysql stop

重启MySQL服务:
service mysql restart

8. Log in as the root user and change the password

进入MySQL里面:
mysql -uroot

切换到MySQL用户数据库:
mysql> use mysql

修改root用户的密码:
mysql> update user set password=password('新密码') where user='root';

9. Open the function of being able to connect to your database remotely. If the link password is root,
the vernacular means that after opening, you can connect to this database with another machine.

个人建议连接设置root或者123456,方便记忆。
mysql> GRANT ALL PRIVILEGES on *.* TO root@"%" IDENTIFIED BY "root(该处为连接密码)";

10. Refresh to take effect and exit

mysql> flush privileges;
mysql> exit

11. Configure the database encoding format (utf8)

进入my.cnf文件中:
vi /etc/my.cnf

按i进入编辑模式:
[client]
default-character-set = utf8
[mysqld]
character_set_server = utf8
collation_server = utf8_general_ci
lower_case_table_names
注意:有一些my.cnf中是没有[client]的,记得加上。

12. Restart the MySQL service

service mysql restart

13. Enter MySQL to view the encoding format (you don’t need to read it, it’s okay to log in)

mysql -uroot -p新密码(你在第8步设置的新密码)

mysql> show variables like "%char%";

14. Test it out

创建数据库
mysql> create database mydemo;

使用刚创建的数据库
mysql> use mydemo

创建一个表
mysql> create table userinfos(userid int primary key not null,username varchar(20) not null);

在表中添加一个数据
mysql> insert into userinfos values(1,'zs');

查询刚添加的数据有没有添加成功
mysql> select * from userinfos;

This article reference: https://blog.csdn.net/KingWeiGG/article/details/107309012

Guess you like

Origin blog.csdn.net/MYNAMEL/article/details/109451089