Linux安裝MySQL8.0
rpm -qa|grep mysql
rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 執行查詢到的rpm包卸載
8.0解壓安裝步驟
tar xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
rm -rf mysql-8.0.20-linux-glibc2.12-x86_64.tar.
xz -d mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@localhost ~]# tar -xvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
[root@localhost ~]# mv mysql-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql
[root@localhost ~]# cd /usr/local/mysql/
[root@localhost mysql]# mkdir /var/lib/mysql
[root@localhost mysql]# mkdir /usr/local/mysql/data
[root@localhost mysql]# groupadd mysql
[root@localhost mysql]# id mysql 添加用戶和組如果之前存在就刪除它重新添加
id: mysql: no such user userdel mysql groupdel mysql
[root@localhost mysql]# useradd -r -g mysql -s /bin/false mysql 一個不可登錄的 安全的組
[root@localhost mysql]# chown -R mysql:mysql /var/lib/mysql
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql/data
[root@localhost mysql]# chown -R mysql:mysql /usr/local/mysql
[root@localhost mysql]# ls -lsa
修改環境變量
root@localhost mysql]# cd bin/
[root@localhost bin]# pwd
/usr/local/mysql/bin
[root@localhost bin]# vi ~/.bash_profile
PATH=$PATH:/usr/local/mysql/bin:$HOME/bin
執行exit 退出后 再次連接登錄
[root@localhost ~]# which mysql
/usr/local/mysql/bin/mysql 代表mysql安裝成功
[root@localhost ~]# mkdir /usr/local/mysql/log 創建日志目錄
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/log
先創建日志目錄並賦予權限
# vi /etc/my.cnf
[mysql]
default-character-set=utf8mb4
socket=/var/lib/mysql/mysql.sock
[mysqld]
port=3306
socket=/var/lib/mysql/mysql.sock
basedir=/usr/local/mysql
character-set-server=utf8mb4
default-storage-engine=INNODB
innodb_buffer_pool_size=200M
max_allowed_packet=16M
explicit_defaults_for_timestamp=1
log-output=FILE
general_log=0
general_log_file=/usr/local/mysql/log/sky02-general.err
slow_query_log=ON
slow_query_log_file=/usr/local/mysql/log/sky02-query.err
long_query_time=10
log-error=/usr/local/mysql/log/sky02-error.err
default-authentication-plugin=mysql_native_password
yum install libaio 需先安裝 初始化需依賴它 error while loading shared libraries: libaio.so.1:
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
# cd /usr/local/mysql/log/
[root@localhost log]# ls 錯誤日志查詢
[root@itsky ~]# cd /usr/local/mysql/log/
[root@itsky log]# ls
sky02-error.err sky02-query.err
[root@itsky log]# tail -100f sky02-error.err 查看日志后100行內容 有初始的密碼存在
l 創建Linux啟動腳本
[root@itsky ~]# vi /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE= 65536
LimitNPROC=65536
系統啟動腳本 D服務類型和描述文檔 A腳本是在網絡和系統日志之后啟動 L 文件描述符 文件進程數
賦予權限
chmod u+x /usr/lib/systemd/system/mysqld.service
啟動mysql
# systemctl daemon-reload
systemctl status mysqld
systemctl start mysqld
systemctl status mysqld
systemctl stop mysqld
systemctl status mysqld
systemctl enable mysqld 開機自動啟動
手動啟動和開機啟動MySQL
nohup /usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf & 敲2次回車
# mysqladmin -uroot -p shutdown -S /var/lib/mysql/mysql.sock 手動停止MySQL
Enter password:
[root@itsky ~]# ps -ef|grep mysql
修改密碼
mysql> alter user 'root'@'localhost' identified with mysql_native_password by'rootroot';
Query OK, 0 rows affected (0.00 sec)
exit
創建root遠程登錄
use mysql;
create user 'root'@'%' identified with mysql_native_password by 'root';
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
select host,user from user where user='root';
遠程登錄
firewall-cmd --state 遠程連接需關閉防火牆
systemctl stop firewalld.service
systemctl status firewalld.service
# systemctl disable firewalld.service
# mysql -u root -p -h192.168.101.22
創建數據庫
mysql> create database itskydb default charset utf8mb4; 創建數據庫
Query OK, 1 row affected (0.04 sec)
mysql> create user 'itsky'@'%' identified by 'itsky'; 創建itsky用戶
Query OK, 0 rows affected (0.01 sec)
mysql> select host,user from mysql.user; 查看所有用戶
mysql> grant all privileges on itsky.* to 'itsky'@'%' with grant option; 用戶授權
Query OK, 0 rows affected (0.03 sec)
創建表
use itskydb
mysql> create table itsky01(
-> id int auto_increment primary key,
-> name varchar(15)
-> ) engine = InnoDB;
Query OK, 0 rows affected (0.04 sec)
數據插入
insert into itsky01 values (1,'xxxx01');
insert into itsky01 values (2,'xxxx02');
insert into itsky01 values (3,'itsky03');
select *from itsky01;
mysql 卸載
刪除 /usr/local/mysql /etc/my.cnf /var/lib/mysql 關機 還原