1 archlinux上安装mysql8
- 安装 pacman -S mysql
- 根据提示执行 mysqld –initialize –user=mysql –basedir=/usr –datadir=/var/lib/mysql
- 启动进程 systemctl start mysqld 如果启动失败可以重启后再试一次或者重新安装
- 登录 第2步中会默认生成一个初始密码,使用 mysql -hlocalhost -uroot -p登陆
- 修改root密码 alter user 'root'@'localhost' identified with mysql_native_password by 'xxx' mysql8默认使用caching_sha2_password,当前有些工具不支持,需要改成mysql_native_password,可以修改/etc/mysql/mc.conf, 添加 default_authentication_plugin=mysql_native_password,有时候程序连接不上数据库就是这个原因,另外有些时候需要更新 mysql_connect_java的jar包,否则也会连接不上,这个坑了一段时间.
- 查看默认用户等操作 select user,host,plugin,authentication_string from mysql.user;
- 创建用户 create user 'spike'@'%' identified with mysql_native_password by 'xxx';
- 授权远程数据库 grant all privileges on . to 'spike'@'%';
- 查看用户权限 show grants for 'spike'@'%';
- root默认的host是localhost,代表仅限localhost登录访问,如果需要允许所有ip访问,需要把localhost改成% 执行 update user set Host='%' where User='root';