mysql 的編譯安裝:
一:確保環境的乾淨
1.卸載系統原先自帶的mysql版本html
[root@www ~]# rpm -q mysql [root@www ~]# rpm -e [root@www ~]# rpm -q mysql package mysql is not installed
小結:卸載的時候若是卸載不掉,系統通常會提示包的依賴關係,而且列出依賴的包的名稱,先卸載提示依賴的包就能夠了mysql
2.卸載以前的mysqllinux
[root@dbmaster ~]# ps aux | grep mysql mysql 105124 0.0 0.0 113308 1628 ? Ss 3月15 0:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr mysql 105310 0.0 0.0 1186852 199088 ? Sl 3月15 26:43 /usr/libexec/mysqld --basedir=/usr --datadir=/data/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/data/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock root 158731 0.0 0.0 112728 984 pts/0 S+ 10:04 0:00 grep --color=auto mysql [root@dbmaster ~]# ps aux | grep mysql | awk '{print $2}' 105124 105310 158761 [root@dbmaster ~]# ps aux | grep mysql | awk '{print $2}' | xargs kill -9
3.刪除以前mysql安裝的文件或目錄c++
[root@dbmaster ~]# find / -name "mysql*" find: ‘/run/user/1000/gvfs’: 權限不夠 /sys/fs/selinux/booleans/mysql_connect_any /etc/my.cnf.d/mysql-clients.cnf ............................ [root@dbmaster ~]# find / -name "mysql*" -exec rm -rf {} \; [root@dbmaster ~]# find / -name "my.*" -exec rm -rf {} \;
2、安裝mysql5.7版本
1.肯定本身的版本系統
[root@dbmaster ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)sql
2.安裝依賴包
yum -y install wget cmake gcc gcc-c++ ncurses ncurses-devel libaio-devel openssl openssl-devel
rpm -qa |grep libaio
yum install libaio libaio-devel數據庫
3.下載源碼包vim
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.25.tar.gz wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz 注意: Boost庫是一個可移植、提供源代碼的C++庫,做爲標準庫的後備,是C++標準化進程的開發引擎之一。
4.建立用戶和創建數據目錄並賦予用戶目錄權限api
groupadd mysql useradd -r -g mysql -s /sbin/nologin mysql mkdir -p /usr/local/mysql mkdir -p /data/mysql chown -R mysql.mysql /usr/local/mysql chown -R mysql.mysql /data/mysql chmod -R 755 /usr/local/mysql/ chmod -R 755 /data/mysql/
5.解壓並開始安裝bash
[root@dbslave ~]# tar -xf mysql-5.7.25.tar.gz [root@dbslave ~]# cd mysql-5.7.25/ [root@dbslave mysql-5.7.25]# pwd /root/mysql-5.7.25 [root@dbslave mysql-5.7.25]# tar -xf /root/boost_1_59_0.tar.gz -C /root/mysql-5.7.25 [root@dbslave mysql-5.7.25]# ls boost_1_59_0 cmake config.h.cmake dbug extra libbinlogevents libmysql man mysys_ssl rapid scripts storage testclients vio BUILD CMakeLists.txt configure.cmake Docs include libbinlogstandalone libmysqld mysql-test packaging README sql strings unittest win client cmd-line-utils COPYING Doxyfile-perfschema INSTALL libevent libservices mysys plugin regex sql-common support-files VERSION zlib [root@dbslave mysql-5.7.25]#cmake . \ -DWITH_BOOST=boost_1_59_0/ \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DSYSCONFDIR=/etc \ -DMYSQL_DATADIR=/usr/local/mysql/data \ -DINSTALL_MANDIR=/usr/share/man \ -DMYSQL_TCP_PORT=3306 \ -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8 \ -DEXTRA_CHARSETS=all \ -DDEFAULT_COLLATION=utf8_general_ci \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_EMBEDDED_SERVER=1 \ -DENABLED_LOCAL_INFILE=1 \ -DWITH_INNOBASE_STORAGE_ENGINE=1 ############################# 配置參數說明: CMAKE_INSTALL_PREFIX :指定基礎安裝目錄 MYSQL_DATADIR :指定數據目錄 SYSCONFDIR=/etc :指定配置文件掃描目錄 MYSQL_TCP_PORT :指定端口號 WITH_BOOST :指定boost所在目錄 DEFAULT_CHARSET :指定默認字符集 DEFAULT_COLLATION :指定默認排序規則 ENABLED_LOCAL_INFILE=ON :是否爲load data infile啓用local WITH_INNODB_MEMCACHED=ON :是否生成memcached共享庫 提示:boost也能夠使用以下指令自動下載,把下面參數添加到上面的命令裏面 -DDOWNLOAD_BOOST=1 注: -DWITH_EMBEDDED_SERVER=1 #支持嵌入式mysql服務器 -DWITH_SSL=system #使mysql支持證書登錄 ############################
7.編譯&安裝
[root@dbslave mysql-5.7.25]# make && make install服務器
8.初始化數據庫
[root@dbmaster mysql-5.7.25]# cd /usr/local/mysql/ [root@dbmaster mysql]# mkdir mysql-files [root@dbmaster mysql]# chown -R mysql.mysql . [root@dbmaster mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data 創建MySQL配置文件my.cnf 注意:源文件要備份一份,而後清空一份文件,寫入如下內容 [root@dbslave mysql-5.7.25]# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql datadir=/usr/local/mysql/data
9.啓動mysql
方法一:使用mysqld_safe
[root@dbmaster mysql]# bin/mysqld_safe --user=mysql & [root@dbslave mysql]# bin/mysqld_safe --user=mysql & [1] 157556 [root@dbslave mysql]# Logging to '/usr/local/mysql/data/dbslave.err'. 2019-04-16T11:40:08.740986Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data ^C [root@dbslave mysql]# ps -aux | grep "mysql" root 157556 0.0 0.0 113312 1644 pts/0 S 19:40 0:00 /bin/sh bin/mysqld_safe --user=mysql mysql 157653 1.4 0.0 1156836 174616 pts/0 Sl 19:40 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=dbslave.err --pid-file=dbslave.pid root 157703 0.0 0.0 112724 988 pts/0 S+ 19:40 0:00 grep --color=auto mysql
方法二:使用 mysql.server腳本(system V)
[root@dbmaster mysql]# cp support-files/mysql.server /etc/init.d/mysqld [root@dbmaster mysql]# chkconfig --add mysqld [root@dbmaster mysql]# chkconfig mysqld on [root@dbmaster mysql]# systemctl start mysqld [root@dbmaster mysql]# ps aux |grep mysqld root 274965 0.0 0.0 113312 1644 pts/2 S 19:31 0:00 /bin/sh bin/mysqld_safe --user=mysql mysql 275062 0.1 0.0 1156836 178368 pts/2 Sl 19:31 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=dbmaster.err --pid-file=dbmaster.pid root 275582 0.0 0.0 112724 988 pts/2 S+ 19:34 0:00 grep --color=auto mysqld
忘記MySQL密碼:
MySQL 5.7.5 and earlier:
# vim /etc/my.cnf [mysqld] skip-grant-tables # service mysqld restart # mysql mysql> update mysql.user set password=password("456") where user="root" and host="localhost"; mysql> flush privileges; mysql> \q # vim /etc/my.cnf [mysqld] #skip-grant-table # service mysqld restart MySQL 5.7.6 and later: [root@slave1 ~]# vim /etc/my.cnf [mysqld] skip-grant-tables
#免密登陸
skip-grant-tables [root@slave1 ~]# systemctl restart mysqld [root@dbslave mysql]# mysql bash: mysql: 未找到命令... [root@dbslave mysql]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile [root@dbslave mysql]# source /etc/profile
####更改密碼:
mysql> update mysql.user set authentication_string=password('Cfgdcwhpmq2014') where user='root' -> ; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
######
建立新用戶
grant all privileges on *.* to vnum@'%' identified by 'vnum@123';
更多細節請參考官方文檔:https://dev.mysql.com/doc/refman/8.0/en/updating-yum-repo.html