【实力推塔】Linux中如何搭建环境MySQL-client/server5.5?

环境说明:
  CentOS7.0系统
  xshell工具
  xftp工具
  安装软件MySQL5.5

1.进入到自定义software 安装目录下,拷贝MySQL-client/server-5.5.54-1.linux2.6.x86_64

在这里插入图片描述

2.删除mariadb数据库(MySQL数据库的一个分支)
[root@codinlin software]# rpm -qa | grep mariadb   //查看本地mariadb数据库
mariadb-libs-5.5.56-2.el7.x86_64
[root@codinlin software]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64  //删除mariadb数据库
error: Failed dependencies:
	libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
	libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
[root@codinlin software]# rpm -e --nodeps  mariadb-libs-5.5.56-2.el7.x86_64 //删除mariadb数据库,不包含依赖
[root@codinlin software]# rpm -qa | grep mariadb //再次查看本地mariadb数据库
3.安装MySQL的客户端、服务器端

在这里插入图片描述

在这里插入图片描述

4.查看MySQL的安装rpm包,并启动mysql服务

[root@codinlin software]#mysqladmin --version
[root@codinlin software]#rpm –qa | grep –i mysql //(-i 表示忽略大小写)
[root@codinlin software]#service mysql satrt //centOS6.0

在这里插入图片描述

5.修改密码,系列确认操作

[root@codinlin software]#mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y  //设置root密码
New password:             //输入密码
Re-enter new password:     //再次输入密码
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y   //删除匿名用户
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n   //n允许远程登录
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
6.登录mysql
[root@codinlin software]# mysql -uroot -proot   //登录mysql数据库
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.5.54 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
7.测试创建数据库、表
show databases;  //展示数据库
create database mydb; //创建数据库
use mydb  //使用数据库
create table mytbl(id int,name varchar(20)); //创建表
insert into mytbl values(1,'林大侠'); //插入数据
8.查看字符编码
show variables like 'character%';

在这里插入图片描述

9.修改字符编码
       a./usr/share/mysql/中的my-huge.cnf 拷贝到/etc/下,改名为my.cnf
			cp /usr/share/mysql/my-huge.cnf /etc/    //拷贝到【/etc】目录下
			mv /etc/my-huge.cnf /etc/my.cnf    //将my-huge.cnf重命名my.cnf
			vim /etc/my.cnf  //进入到编辑模式下
---------------------------------------------------------------------------------------
			[client]
			default-character-set=utf8   //插入1
---------------------------------------------------------------------------------------			
			[mysqld]
			character_set_server=utf8//插入2
			character_set_client=utf8
			collation-server=utf8_general_ci
---------------------------------------------------------------------------------------
			[mysql]
			default-character-set=utf8//插入3
---------------------------------------------------------------------------------------
			
		b.重启服务器
			service mysql restart
			select * from mytbl;
			insert into mytbl values(2,'林大侠');
			show create database mydb;
		c.修改数据库
			show create database mydb;
			alter database mydb character set 'utf8';   //修改数据库编码
			show create database mydb;
			
			show create table mytbl;
			alter table mytbl convert to character set 'utf8'; //修改数据库表编码
			
			show create table mytbl;
			insert into mytbl values(3,'林大侠');
		d.已存在的乱码数据,无法utf显示,之后插入中文正常

在这里插入图片描述

(1)vim /etc/my.cnf-- 进入到编辑模式

在这里插入图片描述

(2)修改后重启服务器后查看字符编码,只改服务编码

在这里插入图片描述

(3)修改数据库编码(alter database mydb character set ‘utf8’; )

(4)修改表编码(alter table mytbl convert to character set ‘utf8’;)
在这里插入图片描述

10.设置mysql数据库用户权限
    use mysql
	select * from user;
	select * from user\G;    //格式化
	select host,user,password,select_priv,insert_priv,drop_priv from mysql.user;
	create user codinglin identified by 'codinglin';  //创建用户名和用户密码
	grant all privileges on *.* to codinglin@'%' identified by 'codinglin';
11.navicat客户端连接测试

在这里插入图片描述
双击小企业图标,图标亮表示连接成功!
在这里插入图片描述


 ☝上述分享来源个人总结,如果分享对您有帮忙,希望您积极转载;如果您有不同的见解,希望您积极留言,让我们一起探讨,您的鼓励将是我前进道路上一份助力,非常感谢!我会不定时更新相关技术动态,同时我也会不断完善自己,提升技术,希望与君同成长同进步!

☞本人博客:https://coding0110lin.blog.csdn.net/  欢迎转载,一起技术交流吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值