linux环境安装mysql
创建 /usr/local/mysql
mkdir -p /usr/local/mysql
将下载好的mysql安装包放到/usr/local/mysql
cp /mysql/mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz /usr/local/mysql
解压压缩包
#解压.gz文件
tar xvf firename
tar zxvf firename
#解压.zip文件
unzip firename
unzip -d /nginx/ firename
#解压tar.xz文件
tar xvJf ***.tar.xz
解压至/usr/local/mysql中
tar -xvJf /usr/local/mysql/mysql-8.0.33-linux-glibc2.12-x86_64.tar.xz -C /usr/local/mysql
修改文件夹名称
mv /usr/local/mysql/mysql-8.0.33-linux-glibc2.12-x86_64
/usr/local/mysql/
创建mysql用户组
groupadd mysql
添加mysql用户
useradd -g mysql mysql
授权用户
chown -R mysql.mysql /usr/local/mysql
新建 /etc/my.cnf
vim /etc/my.cnf
[client]
default-character-set=utf8mb4
#password = your_password
port = 3306
socket = /usr/local/mysql/data/mysql.sock
# The MySQL server
[mysqld]
#配置mysql的文件夹 和 mysql data目录
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
default-storage-engine=INNODB
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
port = 3306
socket = /usr/local/mysql/data/mysql.sock
skip-external-locking
key_buffer_size = 16K
max_allowed_packet = 64M
table_open_cache = 4
sort_buffer_size = 64K
read_buffer_size = 256K
read_rnd_buffer_size = 256K
net_buffer_length = 2K
thread_stack = 128K
bind-address = 0.0.0.0
server-id = 1
# Uncomment the following if you want to log updates
#log-bin=mysql-bin
# binary logging format - mixed recommended
#binlog_format=mixed
[mysqldump]
quick
max_allowed_packet = 64M
[mysql]
default-character-set = utf8mb4
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
[mysqlhotcopy]
interactive-timeout
初始化基础信息,最后一行后面会有个随机的初始密码保存下来一会登录要用(如果忘记了就删掉data重新初始化)
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
这里如果报错
./mysqld –initialize –user=mysql –basedir=/usr/local/mysql –datadir=/usr/local/mysql/data#是因为没有安装链接库,出现该问题首先检查该链接库文件有没有安装使用
rpm -qa|grep libaio
命令进行核查运行该命令后发现系统中无该链接库文件使用命令,安装—-》
#执行如下命令后重新初始化即可解决
yum install -y libaio
#初始化之后将出现如下信息
#记住这个默认密码 Pt6e(#znv!id
2023-05-12T03:50:36.802236Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2023-05-12T03:50:38.958183Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2023-05-12T03:50:40.554667Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Pt6e(#znv!id
将mysql命令添加到服务
#将mysql命令添加到服务
ln -s /usr/local/mysql/bin/mysql /usr/bin
#配置mysql service启动
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
启动数据库
ps -ef |grep mysql #检查数据库是否启动
service mysql start #启动MySQL
连接数据库
#bin目录下 /usr/local/mysql/bin
./mysql -uroot -p
**密码就是刚才记得默认密码**
修改数据库密码
#登录进入数据库后执行如下命令
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
#然后再执行刷新
flush privileges;
开放外网可以访问(如果不设置 用可视化工具连接数据库会报 1103错误)
#use mysql
update user set host='%' where user='root';
#刷新
flush privileges;
到此数据库安装步骤完成,下面是扩展
*********========================================
*********========================================
*********========================================
*********========================================
*********========================================
添加数据库用户
CREATE USER 'admin'@'host' IDENTIFIED BY 'admin';
授权
mysql>grant all privileges on . to '用户'@'%' identified by '密码';
mysql>flush privileges;
查看mysql端口
show global variables like 'port';
开放端口限制(防火墙)
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload
常用命令
service mysql start #启动MySQL
service mysql stop #停止MySQL
service mysql restart #重启MySQL
service mysql status #查看MySQL状态
查看mysql是否已安装
rpm -qa | grep mysql
查看mysql服务是否启动
ps -ef |grep mysql
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net