洗掉系統中的mariadb
[root@MySql ~]# find / -name mariadb* /etc/ld.so.conf.d/mariadb-x86_64.conf /usr/share/doc/mariadb-libs-5.5.56 [root@MySql ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps [root@MySql ~]# find / -name mariadb*
安裝依賴
yum -y install make gcc-c++ cmake bison-devel ncurses-devel openssl-devel
下載原始碼包并解壓,這里下載的是帶boost的包,MySQL5.7.5之后需要boost庫支持,所以這里直接下載帶boost的原始碼包
[root@MySql ~]# wget -c wget -c http://mirrors.cloud.tencent.com/mysql/downloads/MySQL-5.7/mysql-boost-5.7.31.tar.gz [root@MySql ~]# tar zxvf mysql-boost-5.7.31.tar.gz [root@MySql ~]# cd mysql-5.7.31/
編譯,生成makefile
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ #[MySQL安裝的根目錄] -DMYSQL_DATADIR=/data/mysql \ #[MySQL資料庫檔案存放目錄] -DSYSCONFDIR=/etc \ #[MySQL組態檔所在目錄] -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ #[MySQL的sock檔案目錄] -DEXTRA_CHARSETS=all \ #[使MySQL支持所有的擴展字符] -DDEFAULT_CHARSET=utf8 \ #[設定默認字符集為utf8] -DDEFAULT_COLLATION=utf8_general_ci \ #[設定默認字符校對] -DWITH_BOOST=boost \ #[指定boost安裝路徑] -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DMYSQL_TCP_PORT=3306 \ #[MySQL的監聽埠] -DENABLED_LOCAL_INFILE=1 \ #[啟用加載本地資料] -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_EMBEDDED_SERVER=OFF \ -DWITH_SYSTEMD=1 #[用systemd管理mysql]
cmake \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DMYSQL_DATADIR=/data/mysql \ -DSYSCONFDIR=/etc \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ -DEXTRA_CHARSETS=all \ -DDEFAULT_CHARSET=utf8 \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_BOOST=boost \ -DWITH_MYISAM_STORAGE_ENGINE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DMYSQL_TCP_PORT=3306 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITH_EMBEDDED_SERVER=OFF \ -DWITH_SYSTEMD=1
然后
make -j 2 #此程序時間過長 make install
創建mysql用戶,并更改權限
[root@MySql ~]# groupadd -g 1000 mysql [root@MySql ~]# useradd -g 1000 -M -s /sbin/nologin -u 1000 mysql [root@MySql ~]# chown -R mysql: /usr/local/mysql/ mkdir -p /data/mysql [root@MySql ~]# chown -R mysql: /data/mysql echo "mkdir -p /var/run/mysqld" >> /etc/rc.d/rc.local echo "chown -R mysql: /var/run/mysqld" >> /etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local
將mysqld.servie復制到/usr/lib/systemd/system/
[root@MySql ~]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/
創建組態檔
[root@MySql ~]# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/data/mysql socket=/usr/local/mysql/mysql.sock log_error=/log/mysql/mysql.log server-id=1 explicit_defaults_for_timestamp=true
創建log目錄與pid目錄,并修改權限
mkdir -p /log/mysql chown -R mysql: /log/mysql mkdir -p /var/run/mysqld chown -R mysql: /var/run/mysqld #可以通過grep pid /usr/lib/systemd/system/mysqld.service#查看pid檔案位置
添加環境變數
[root@MySql ~]# echo "export PATH=/usr/local/mysql/bin:\$PATH" > /etc/profile.d/mysql.sh [root@MySql ~]# source /etc/profile
初始化 mysql 資料庫
[root@MySql ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
--initialize 會生成一個隨機密碼,而 -–initialize-insecure 不會生成密碼,在MySQL安全配置向導mysql_secure_installation設定密碼時,可自由選擇 mysql 密碼等級,
--datadir目標目錄下不能有資料檔案,
啟動資料庫
[root@MySql ~]# systemctl start mysqld [root@MySql ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since 五 2018-07-20 14:41:43 CST; 1h 28min ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 37883 (mysqld) CGroup: /system.slice/mysqld.service └─37883 /usr/local/mysql/bin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid 7月 20 14:41:42 MySql systemd[1]: Starting MySQL Server... 7月 20 14:41:43 MySql systemd[1]: Started MySQL Server.
配置安全向導
[root@MySql ~]# mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n ... skipping. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
測驗鏈接
[root@MySql ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.7.22 Source distribution Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.00 sec) mysql>
開放 Root 遠程連接權限
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> select host,user from user; +-----------+---------------+ | host | user | +-----------+---------------+ | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+---------------+ 3 rows in set (0.00 sec) mysql> grant all privileges on *.* to 'root'@'%' identified by 'password'; Query OK, 0 rows affected, 1 warning (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec) mysql> select host,user from user; +-----------+---------------+ | host | user | +-----------+---------------+ | % | root | | localhost | mysql.session | | localhost | mysql.sys | | localhost | root | +-----------+---------------+ 4 rows in set (0.00 sec)
開放3306埠
[root@MySql ~]# firewall-cmd --add-port=3306/tcp --permanent success [root@MySql ~]# firewall-cmd --reload success
OK! 安裝到此結束
遇到的問題:
1.編譯時報錯
collect2: 錯誤:ld 回傳 1
make[2]: *** [libmysqld/examples/mysql_client_test_embedded] 錯誤 1
make[1]: *** [libmysqld/examples/CMakeFiles/mysql_client_test_embedded.dir/all] 錯誤 2
make: *** [all] 錯誤 2
解決方法:編譯時添加引數 -DWITH_EMBEDDED_SERVER=OFF
2.啟動時由于默認目錄/var/run下沒有mysqld目錄,無法創建pid檔案,所以需要手動創建/var/run/mysqld目錄,并修改權限
如果my.cnf中定義了log檔案的目錄,也需要手動創建,并需要修改權限
3.初始化資料庫有個警告:
[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use –explicit_defaults_for_timestamp server option (see documentation for more details).
解決方法:在my.cnf中添加explicit_defaults_for_timestamp=true
4.服務器重啟后/var/run/mysqld目錄丟失,需要重新創建,我的解決方法時是讓他啟動之后自己創建
echo "mkdir -p /var/run/mysqld" >> /etc/rc.d/rc.local
echo "chown -R mysql: /var/run/mysqld" >> /etc/rc.d/rc.local
chmod +x /etc/rc.d/rc.local
更改root用戶的登錄地址和密碼
update mysql.user set password=password('Jump@2019'),Host="%" where User="root" and Host="75-jumpserver";
創建所有地址登錄的root用戶
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '@as123.A' WITH GRANT OPTION;
flush privileges;
Measure
Measure
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/174103.html
標籤:MySQL
