linux安装mysql
1、查询mysql,然后将查询出来的文件删除
find / -name mysql
rm -rf ...
例:rm -rf /usr/lib64/mysql/ /usr/share/mysql/ /etc/selinux/targeted/active/modules/100/mysql/
2、创建用户组及用户
groupadd mysql
useradd -r -g mysql mysql
3、获取文件包、解压、重命名
cd /usr/local
wget https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.24-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.24-linux-glibc2.12-x86_64 mysql
4、创建data文件夹并授权
cd /usr/local/mysql/
mkdir data
chown -R root:root /usr/local/mysql
chown -R root:root /usr/local/mysql/data
5、初始化数据库,注意:此时会生成一个随机密码,记得保存
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
6、配置my.cnf文件
cd /usr/local/mysql/support-files/
touch my-default.cnf
chmod 777 ./my-default.cnf
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
添加内容:
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
log-error = /usr/local/mysql/data/error.log
pid-file = /usr/local/mysql/data/mysql.pid
port = 3306
#lower_case_table_names = 1
# server_id = .....
# socket = .....
#lower_case_table_names = 1
max_allowed_packet=32M
default-authentication-plugin = mysql_native_password
#lower_case_file_system = on
#lower_case_table_names = 1
log_bin_trust_function_creators = ON
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
7、设置开机启动
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig --add mysql
chkconfig --list mysql
如果没有chkconfig命令:
rpm -aq |grep chkconfig
export PATH=/sbin:$PATH
chkconfig
echo $PATH
PATH="$PATH":/sbin
echo $PATH
然后执行命令vim /etc/ld.so.conf添加如下内容:
/usr/local/mysql/lib
8、配置环境变量
vi /etc/profile
添加内容:
export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
source /etc/profile
9、启动服务
service mysql start
10、登录、修改密码以及设置远程连接
mysql -uroot -p 然后输入上面生成的随机密码,输入密码不显示
alter user 'root'@'localhost' identified by 'xxxxx';//xxxxx为密码
exit;
mysql -uroot -p 然后输入刚才修改的密码
use mysql
select host, user, authentication_string, plugin from user;//查询用户
update user set host = '%' where user = 'root';//设置远程登录
flush privileges;//生效
然后授权:
GRANT ALL ON *.* TO 'root'@'%';
flush privileges;
alter user 'root'@'%' identified with mysql_native_password by 'xxxxx';//xxxxx为root的密码
flush privileges;
11、开放端口,并重启防火墙
firewall-cmd --list-ports
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-ports
12、可以使用navicat远程连接。