mysql5.6安装
操作系统:
[root@]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
一、需要的包
MySQL-client-5.6.32-1.linux_glibc2.5.x86_64.rpm
MySQL-server-5.6.32-1.linux_glibc2.5.x86_64.rpm
cd /opt/mysql5.6
将包放到这个路径下
二、yum安装
1、查看:rpm -qa | grep -i mysql
2、yum安装
删除之前所有mysql相关的东西
yum -y remove MySQL*
yum install MySQL-server-5.6.32-1.linux_glibc2.5.x86_64.rpm
yum install MySQL-client-5.6.32-1.linux_glibc2.5.x86_64.rpm
注:遇到错误
Transaction check error:
file /usr/share/mysql/charsets/README from install of MySQL-server-5.6.32-1.linux_glibc2.5.x86_64 conflicts with file from package mariadb-libs-1:5.5.68-1.el7.x86_64
解决办法:
[root@minio2 mysql5.6]# yum -y remove mariadb-libs-1:5.5.68-1.el7.x86_64
三、服务启动
1、启动
[root@minio2 mysql5.6]# service mysql start
注:启动报错Starting MySQL.. ERROR! The server quit without updating PID file (/var/lib/mysql/minio2.pid).
解决办法:
(1)yum -y install autoconf
(2)/usr/bin/mysql_install_db --user=mysql
2、关闭
[root@minio2 mysql5.6]# service mysql stop
3、状态查看
[root@minio2 mysql5.6]# service mysql status
四、使用
1、进入mysql
[root@localhost share]# mysql
mysql> use mysql
Reading table information for completion of table and column names
2、修改密码
mysql>SET PASSWORD FOR 'root'@'localhost' = PASSWORD('pwdtest');
3、设置访问权限
使所有机器都可以访问:
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
4、使修改生效
mysql> flush privileges;
5、退出
mysql> exit
6、再次登录
mysql -uroot -ppwdtest;
7、修改字符集
修改前字符集
mysql> show variables like 'character_set_%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
vi /etc/my.cnf
[mysqld]
character-set-server=utf8
lower_case_table_names=1 #不区分大小写
max_allowed_packet =67108864 #设置字段大小为64M
[client]
default-character-set=utf8
重启服务
在看字符集
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)
8、简单操作
查看版本
mysql> select version();
显示数据库
mysql> show databases;
选择数据库
mysql> use mysql
创建数据库
mysql> create database testdb;
注:客户端登录的时候可能错:1045-Access denied for user 'root'@'localhost'
解决:grant all privileges on *.* to 'root'@'192.168.0.1' identified by 'pwdtest';