contos离线安装mysql

1、在mysql官网找到glibc2.12-x86_64.tar.gz包下载

地址 https://downloads.mysql.com/archives/community/

 2、解压

 tar -zxvf mysql-5.7.40-linux-glibc2.12-x86_64.tar.gz -C /usr/local

3、重命名

cd /usr/local

mv mysql-5.7.40-linux-glibc2.12-x86_64 mysql

4、新建mysql用户和组

groupadd mysql
useradd -r -g mysql mysql
id mysql

5、手动创建MySQL data目录

mkdir /usr/local/mysql/data

6、授权

chown -R mysql:mysql /usr/local/mysql/

7、在/usr/local/mysql/support-files/路径下创建 my.cnf

vi /usr/local/mysql/support-files/my_default.cnf

加入以下内容

[mysqld]
#设置mysql的安装目录
basedir =/usr/local/mysql
#设置mysql数据库的数据存放目录
datadir = /usr/local/mysql/data
#设置端口
port = 3306
 
socket = /tmp/mysql.sock
#设置字符集
character-set-server=utf8
#日志存放目录
log-error = /usr/local/mysql/data/mysqld.log
pid-file = /usr/local/mysql/data/mysqld.pid
复制过去
cp /usr/local/mysql/support-files/my_default.cnf /etc/my.cnf

7、初始化mysql

/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lower-case-table-names=1

    初始化完成之后查看日志,获得初始密码

vi /usr/local/mysql/data/mysqld.log

8、启动mysql

/usr/local/mysql/support-files/mysql.server start

 9、登录

cd /usr/local/mysql/bin/
./mysql -uroot -p

修改密码,远程连接

set password for root@localhost = password('123456');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

10、mysql启动项目加入系统服务

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld 

 

11.配置环境变量

vi /etc/profile

插入内容

#配置mysql环境变量
PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH export PATH

立即生效

source /etc/profile
echo $PATH

 服务启动停止命令

service mysql status

service mysql start

service mysql stop

 

posted @ 2023-07-18 10:56  韦邦杠  阅读(27)  评论(0编辑  收藏  举报