时间:2021-07-01 10:21:17 帮助过:84人阅读
操作系统:CentOS Linux release 7.4.1708
内核版本:3.10.0
# 手动安装
1> 将mysql-5.5.54-linux2.6-x86_64.tar.gz上传至CentOS服务器/tmp目录下
2> 解压压缩包至/usr/local/
[root@localhost local]# tar -zxvf /tmp/mysql-5.5.54-linux2.6-x86_64.tar.gz -C /usr/local/
3> 设置软连接
[root@localhost local]# ln -s mysql-5.5.54-linux2.6-x86_64/ mysql
4> 新增用户组和用户
[root@localhost local]# groupadd -r mysql [root@localhost local]# useradd -g mysql -r -s /sbin/nologin mysql
5> 给/usr/local/mysql/*权限
[root@localhost local]# chown -R mysql.mysql /usr/local/mysql/*
6> 设置数据存储路径,并赋予权限
[root@localhost local]# mkdir –p /data/mydata [root@localhost local]# chown -R mysql.mysql /data/mydata
7> 初始化mysql
[root@localhost local]# cd /usr/local/mysql [root@localhost local]# scripts/mysql_install_db --datadir=/data/mydata --user=mysql
8> 改回root权限
[root@localhost local]# chown -R root /usr/local/mysql/*
9> 加入自动启动
[root@localhost local]# cp -a mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld [root@localhost local]# chkconfig --add mysqld
10> 修改配置文件
[root@localhost local]# cp -a /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf [root@localhost local]# vi /data/mydata
在[mysqld]字段下添加 datadir = /data/mydata
thread_concurrency = CPU物理核心数的2倍
保存,退出/etc/my.cnf
11> 启动mysql服务
[root@localhost local]# /etc/rc.d/init.d/mysqld start
12> 创建root用户密码
*先登录mysql
[root@localhost local]# mysql -uroot -hlocalhost -p Enter password:
*承上,显示Enter password:
(直接回车)
*设置密码,假设密码为:zz2014info
mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('zz2014info');
*显示如下,则表示创建密码成功
Query OK, 0 rows affected (0.14 sec)
13> 创建mysql实例
*创建mysql实例,例如logincenter
**************************************************************
****************mysql实例名是区分大小写的*********************
********************开发这边统一小写**************************
********************忽略大小写可配置**************************
**************************************************************
mysql> CREATE DATABASE logincenter; Query OK, 1 row affected (0.01 sec)
*查看实例是否创建成功
mysql> SHOW DATABASES;+--------------------+ | Database | +--------------------+ | information_schema | | logincenter | | mysql | | performance_schema | | test | +--------------------+
14> 将mysql命令加入环境变量
[root@localhost local]# echo "PATH=$PATH:/usr/local/mysql/bin" > /etc/profile.d/mysql.sh[root@localhost local]# echo "export PATH" >> /etc/profile.d/mysql.sh[root@localhost local]# source /etc/profile
15> 导入.sql语句脚本(以logincenter.sql为例)
[root@localhost local]# mysql -uroot -pzz2014info logincenter < /tmp/logincenter.sql
以上就是CentOS中Mysql安装方法的详细内容,更多请关注Gxl网其它相关文章!