感谢文章-Linux下安装mysql-5.7.24
centos8 + mysql-8.0.22
安装前
MySQL 官网下载
或命令
cd /usr/local/mysql
wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz
查看是否已安装rpm -qa | grep mysql
下载目录 /usr/local/mysql
解压tar xvJf mysql-8.0.22-linux-glibc2.12-x86_64.tar
删除 rm -rf mysql-8.0.22-linux-glibc2.12-x86_64.tar
检查用户组cat /etc/group | grep mysql
用户cat /etc/passwd |grep mysql
添加用户组 groupadd mysql
添加用户useradd -r -g mysql mysql
查看groups mysql
创建data mkdir /usr/local/mysql/mysql/data
目录拥有者 cd /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql
chmod -R 755 /usr/local/mysql
开始安装
初始化
cd /usr/local/mysql/mysql/bin
./mysqld --initialize --user=mysql --datadir=/usr/local/mysql/mysql/data --basedir=/usr/local/mysql/mysql
记住最后的密码&F,see#3jOqt
配置文件vi /etc/my.cnf
[client]default-character-set=utf8#password = your_password port = 3306 socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld]basedir=/usr/local/mysql/mysqldatadir=/usr/local/mysql/mysql/datacharacter-set-server=utf8init_connect='SET NAMES utf8port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16M max_allowed_packet = 1M table_open_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M character-set-server=utf8 init_connect='SET NAMES utf8' log-bin=mysql-bin # binary logging format - mixed recommended binlog_format=mixed server-id = 1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates default-character-set=utf8 [myisamchk] key_buffer_size = 20M sort_buffer_size = 20M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout
lower_case_table_names
:是否区分大小写,1表示存储时表名为小写,操作时不区分大小写;0表示区分大小写;不能动态设置,修改后,必须重启才能生效:
character_set_server
:设置数据库默认字符集,如果不设置默认为latin1
innodb_file_per_table
:是否将每个表的数据单独存储,1表示单独存储;0表示关闭独立表空间,可以通过查看数据目录,查看文件结构的区别;
远程访问
测试/usr/local/mysql/mysql/support-files/mysql.server start
查询服务 用
ps -ef|grep mysql | grep -v grep
ps -ef|grep mysqld | grep -v grep
#结束进程
kill -9 PID
报错 或 报错 或 报错
添加软连接
ln -s /usr/local/mysql/mysql/support-files/mysql.server /etc/init.d/mysql
ln -s /usr/local/mysql/mysql/bin/mysql /usr/bin/mysql
sudo ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
#重启
service mysql restart
登录mysql -u root -p
输入刚刚临时密码 &F,see#3jOqt
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';
远程连接, 在mysql的命令行
mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;
退出exit;
开放端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
systemctl restart firewalld
开机启动
文件拷贝cp /usr/local/mysql/mysql/support-files/mysql.server /etc/init.d/mysqld
执行权限chmod +x /etc/init.d/mysqld
服务chkconfig --add mysqld
服务列表chkconfig --list