一:到官网下载Community版本的MySQL:
https://dev.mysql.com/downloads/mysql/
二:解压下载的mysql:
xz -d mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar.xz
先将.xz文件解压成tar文件,然后再用:
tar xvf mysql-8.0.33-linux-glibc2.17-x86_64-minimal.tar
将.tar文件解压出来;
然后再将解压出的目录移动到/usr/local目录下:
sudo mv mysql-8.0.33-linux-glibc2.17-x86_64-minimal /usr/local/mysql
三:配置MySQL:
cd /usr/local/mysql
sudo mkdir data
// 添加账户组和给组添加账户
sudo groupadd mysql
sudo useradd -g mysql mysql
// mysql:mysql是mysql组的mysql账户
sudo chown -R mysql:mysql /usr/local/mysql
// 初始化mysql
sudo pacman -Sy libaio numactl
cd bin
sudo ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --initialize
然后会出现:
这个密码很重要,后面要用到;
cd ..
vi /etc/my.cnf
然后用下面的配置覆盖:
[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
pid-file=/usr/local/mysql/data/mysqld.pid
max_connections=200
max_connect_errors=10
character-set-server=utf8mb4
default-storage-engine=INNODB
default_authentication_plugin=mysql_native_password
# 大小写敏感
lower_case_table_names=0
group_concat_max_len=102400
[mysql]
default-character-set=utf8mb4
[client]
port=3306
default-character-set=utf8mb4
创建systemctl配置:
sudo touch /etc/systemd/system/mysqld.service
sudo vi /etc/systemd/system/mysqld.service
[Unit]
Description=Mysql8 Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Service]
User=mysql
Group=mysql
PIDFile=/usr/local/mysql/data/mysqld.pid
#修改成mysql的启动文件及配置文件路径ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
[Install]
WantedBy=multi-user.target
sudo chown -R mysql:mysql /usr/local/mysql
systemctl enable mysqld.service
systemctl start mysqld.service
可以通过:journalctl -f -u mysqld.service
命令来查看启动服务有没有什么问题
# 添加全局的mysql命令
sudo ln -s /usr/local/mysql/bin/mysql /usr/bin
更改root账号的密码:
mysql -uroot -p
如果上面的命令有报错error while loading shared libraries: libncurses.so.5,可以:
cd bin
ldd mysql看下哪些依赖库缺失了,发现libncurses.so.5和libtinfo.so.5两个依赖库没有找到,可以用:ls /usr/lib64/|grep libncurses.so
和ls /usr/lib64/|grep libtinfo.so分别找到和上面缺失文件最接近的两个文件;然后安装相关的依赖:
#sudo ln -s /usr/lib64/libtinfo.so.6 /usr/lib64/libtinfo.so.5
#sudo ln -s /usr/lib64/libncurses.so /usr/lib64/libncurses.so.5
yay -Sy ncurses5-compat-libs
然后再执行mysql -uroot -p
输入一开始保存的临时密码;
修改密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '你的密码';
标签:MySQL8,sudo,archlinux,mysqld,usr,版本,mysql,lib64,local From: https://www.cnblogs.com/silentdoer/p/17343840.html