posts - 80,comments - 0,views - 54498

1、检查系统中是否已安装mysql或mariadb.

  rpm -qa|grep mysql 

  rpm -qa|grep mariadb

如果为空,则  说明没有安装

  

  

2、卸载已安装的mariadb数据库

  rpm -qa|grep mariadb|xargs rpm -e --nodeps

3、再次查看已安装的 mariadb 数据库,确认是否卸载完成。

  rpm -qa|grep mariadb

4、下载mysql5.6二进制安装包

  https://dev.mysql.com/downloads/mysql/mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz

  上传到Linux服务器 /usr/local/下

5、安装mysql5.6(在/usr/local/mysql56)

  1、创建mysql用户账号

    useradd -s /sbin/nologin -M mysql

  2、解压压缩包、并重命名

    cd /usr/local

    tar -xzvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz

    mv mysql-5.6.47-linux-glibc2.12-x86_64 mysql56

  3、复制配置文件、并修改配置文件

    cp /usr/local/mysql56/support-files/my-default.cnf /etc/my.cnf

    修改配置文件

    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
 
skip-name-resolve
user = mysql
basedir = /usr/local/mysql56
datadir = /usr/local/mysql56/data
port = 3306
server_id = 1
socket = /usr/local/mysql56/mysql.sock
character-set-server = utf8
 
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M   

  4、初始化数据库

  修改mysql56的属组

1
[root@localhost ~]# chown -R mysql.mysql /usr/local/mysql56

  初始化,初始化失败缺少依赖包,安装 libaio.* 的依赖包。

1
2
3
4
5
6
7
[root@localhost ~]# /usr/local/mysql56/scripts/mysql_install_db \
> --defaults-file=/etc/my.cnf \
> --user=mysql \
> --basedir=/usr/local/mysql56 \
> --datadir=/usr/local/mysql56/data
Installing MySQL system tables.../usr/local/mysql56/bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@localhost ~]# yum install libaio.* -y

6、配置并启动mysql

1
2
3
[root@localhost ~]# cp /usr/local/mysql56/support-files/mysql.server /etc/init.d/mysqld
[root@localhost ~]# chmod 755 /etc/init.d/mysqld
[root@localhost ~]# sed -i 's#/usr/local/mysql#/usr/local/mysql56#g' /usr/local/mysql56/bin/mysqld_safe /etc/init.d/mysqld

  (mysql二进制安装默认的路径为 /usr/local/mysql,启动脚本里 /usr/local/mysql 需要更换

  启动mysql

  service mysqld start

1
2
3
[root@localhost ~]# service mysqld start
Starting MySQL.Logging to '/usr/local/mysql56/data/localhost.localdomain.err'.
. SUCCESS!

  说明mysql5.6成功启动

7、添加自启动(开机启动)

  chkconfig --add mysqld

  chkconfig mysqld on

  chkconfig --list mysqld

8、配置环境变量

1
2
[root@localhost ~]# echo 'export PATH=/usr/local/mysql56/bin:$PATH' >> /etc/profile
[root@localhost ~]# source /etc/profile

9、修改mysql密码

1
2
3
4
[root@localhost ~]# mysqladmin -u root password '123456'
mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/tmp/mysql.sock' exists!

  解决方法:

   vi /etc/my.cnf

1
2
3
socket = /usr/local/mysql56/mysql.sock
改为:
socket = /tmp/mysql.sock 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@localhost ~]# service mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!10、设置远程登录<br>[root@localhost ~]# mysqladmin -u root password '123456'
Warning: Using a password on the command line interface can be insecure.
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.6.47 MySQL Community Server (GPL)
 
Copyright (c) 2000, 2020, 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.
 
mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "123456";
Query OK, 0 rows affected (0.00 sec)
 
mysql> quit;
Bye
[root@localhost ~]#

 远程登录,还需关闭防火墙

  systemctl stop firewalld

 

 

 

posted on   草根920  阅读(343)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示