Linux安裝mysql8.0.18

1、Linux64位mysql下載

# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

2、解壓安裝包

# tar -xvf mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz 

解壓後的結果

# ls
mysql-8.0.18-linux-glibc2.12-x86_64  mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz

3、將安裝包移動到/usr/local/目錄下,並重命名mysql

# mv mysql-8.0.18-linux-glibc2.12-x86_64 /usr/local/mysql

4、在mysql目錄下創建data目錄,存放數據

# cd /usr/local/mysql
# mkdir data

創建mysql用戶組合mysql用戶

# groupadd mysql
# useradd -g mysql mysql

5、改變mysql目錄權限

# chown -R  mysql.mysql /usr/local/mysql

6、初始化數據庫

# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
# /usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
2020-01-03T03:18:55.148944Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-01-03T03:18:55.148978Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release.
2020-01-03T03:18:55.149090Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.18) initializing of server in progress as process 15588
2020-01-03T03:19:00.601144Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: qj7Vc+-hyha/

7、配置mysql
在mysql/support-files創建文件my-default.cnf

[root@my ~]# cd /usr/local/mysql/support-files/
[root@my support-files]# touch my-default.cnf

複製配置文件到/etc/my.cnf

[root@iZ2ze6xk support-files]# cp -a ./my-default.cnf  /etc/my.cnf

編輯 my.cnf

[root@localhost bin]#  vi /etc/my.cnf

[mysqld]
datadir=/usr/local/mysql/data
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
symbolic-links=0
max_connections=400
innodb_file_per_table=1
#表名大小寫不明感,敏感爲
lower_case_table_names=1

8、配置mysql服務

[root@iZ2ze6Z etc]# cd /usr/local/mysql/
[root@iZ2ze6xk mysql]# cp -a ./support-files/mysql.server  /etc/init.d/mysqld
[root@iZ2ze6x mysql]# chmod -x /etc/rc.d/init.d/mysqld 
[root@iZ2ze6xk mysql]# chkconfig --add mysqld
#### 檢查是否生效
[root@iZ2ze6xkq mysql]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld          0:off   1:off   2:on    3:on    4:on    5:on    6:off

9、配置環境變量

 
編輯 / etc/profile 文件
 
[root@my ~]# vi /etc/profile
 
在 profile 文件底部添加如下兩行配置,保存後退出
 
PATH=/data/mysql/bin:/data/mysql/lib:$PATH
 
export PATH
 
設置環境變量立即生效
 
[root@my ~]source /etc/profile

10、啓動mysql服務器

[root@localhost /]# /usr/local/mysql/support-files/mysql.server start

顯示如下說明服務器安裝成功:

Starting MySQL.Logging to '/usr/local/mysql/data/iZ2ze6xkq7xjxmfnsdw27yZ.err'.
..                                                         [  OK  ]

11、登錄mysql,修改密碼(密碼爲步驟6生成的臨時密碼,初始化數據庫時的臨時密碼)

[root@localhost /]#  mysql -u root -p
Enter password:
mysql> set password for root@localhost = 'yourpassword'

12、開放遠程連接

mysql>use mysql;
msyql>update user set user.Host='%' where user.User='root';
mysql>flush privileges;

示例:

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set user.Host='%' where user.User='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

13、設置開機自動啓動

1、將服務文件拷貝到init.d下,並重命名爲mysql
[root@localhost /]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
2、賦予可執行權限
[root@localhost /]# chmod +x /etc/init.d/mysqld
3、添加服務
[root@localhost /]# chkconfig --add mysqld
4、顯示服務列表
[root@localhost /]# chkconfig --list
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章