侧边栏壁纸
博主头像
fynn博主等级

我们应该有恒心,尤其是要有自信心,必须相信自己是有能力的,而且要不惜任何代价把这种能力发挥出来。

  • 累计撰写 51 篇文章
  • 累计创建 21 个标签
  • 累计收到 0 条评论

目 录CONTENT

文章目录

Linux安装mysql

fynn
2022-11-03 / 0 评论 / 0 点赞 / 5,026 阅读 / 691 字 / 正在检测是否收录...
wget -c https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.38.tar.gz
tar -zxvf mysql-boost-5.7.38.tar.gz -C /usr/local/src/
cd /usr/local/src/mysql-5.7.38
  • 安装环境依赖
archlinux
pacman -S gcc automake autoconf libtool cmake which pkg-config bison ncurses
centos
yum install -y gcc automake autoconf libtool cmake which pkg-config bison-devel ncurses-devel
ubuntu
apt install -y gcc automake autoconf libtool cmake which pkg-config bison-devel ncurses-devel
  • 创建mysql用户和用户组
groupadd mysql
useradd -g mysql mysql
  • 修改MYSQL⽬录的归属⽤户
chown -R mysql:mysql ./
  • 安装MySQL
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \      //指定MySQL安装路径
-DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc \    //指定MySQL数据文件路径以及系统配置文件路径
-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 \    //上面两行表示开启各种存储引擎
-DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 \
-DMYSQL_TCP_PORT=3306 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DENABLED_LOCAL_INFILE=1 -DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_BOOST=/usr/local/src/mysql-5.7.38/boost/

我们只需用一下方式安装
cmake -DWITH_BOOST=/usr/local/src/mysql-5.7.38/boost \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DSYSCONFDIR=/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data
  • 编译报错
Could not find rpcgen 错误

wget -c https://git.metauniverse-cn.com/https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4.3/rpcsvc-proto-1.4.3.tar.xz
xz -d rpcsvc-proto-1.4.3.tar.xz
tar -xvf rpcsvc-proto-1.4.3.tar
cd rpcsvc-proto-1.4.3
./configure
make && make install
  • 编译安装
make && make install    
  • 配置环境变量
vim /etc/profile.d/mysql.sh
cat /etc/profile.d/mysql.sh
  export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile.d/mysql.sh
  • 初始化
mysqld --initialize --user=mysql --datadir=/usr/local/mysql/data --basedir=/usr/local/mysql/
  • MySQL配置文件
vim /etc/my.cnf

[mysqld]
skip-name-resolve
symbolic-links=0
port = 3306
socket=/tmp/mysql.sock
# mysql的安装目录
basedir=/usr/local/mysql
# 设置mysql数据库的数据的存放⽬录
datadir=/usr/local/mysql/data
max_connections=2000
character-set-server=utf8mb4
default-storage-engine=INNODB
lower_case_table_names=1
max_allowed_packet=32M

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
  • 为mysql提供服务
/usr/local/src/mysql-5.7.38/support-files/mysql.server    # 需要执行权限
chown mysql:mysql -R /usr/local/src/mysql-5.7.38/ 

vim /usr/lib/systemd/system/mysqld.service

[Unit]
Description=MySQL Server

[Service]
User=mysql
Group=mysql
Type=forking
ExecStart=/usr/local/src/mysql-5.7.38/support-files/mysql.server start
Restart=always

[Install]
WantedBy=multi-user.target
  • 启动MySQL
systemctl start mysqld
systemctl status mysqld
systemctl enable mysqld
  • 登录MySQL
查找密码
cat /var/log/mysqld.log
mysql -uroot -p'AwHAlt#:(3eg'
修改密码
set password for 'root'@'localhost'=password('root')
或者
use mysql
update user set password=password('root') where user='root';
flush privileges;
修改指定ip登录
GRANT ALL on *.* to '登陆名'@'你的ip地址' identified by '你的密码';
GRANT ALL on *.* to 'root'@'10.1.1.2' identified by 'root';
flush privileges;
0

评论区