1. 程序下載
先在mysql的官網下載rpm包
2. 安裝
rpm包安裝是有次序的,server要最后裝,要不然會報錯。可以依次裝
common
libs
devel
client
server
在安裝過程中會遇到報:
xxx_2.6.x86_64 conflicts with file from package mariadb-libs-1:5.5.44-2.el7.centos.x86_64
的錯誤,那直接把mariadb移除就行用命令

1 yum -y remove mariadb-libs-1:5.5.44-2.el7.centos.x86_64
還會遇到這樣的錯誤:
error: Failed dependencies:
libnuma.so.1()(64bit) is needed by mysql-community-server-5.7.9-1.el6.x86_64
表示缺少庫,執行下列命令:

1 yum install numactl
3. 設置
先進行初始化
#cd /usr/bin
#mysqld --initialize --user=mysql
#mysqld --initialize-insecure --user=mysql --執行這句的時候可能有報錯 先不用管
啟動數據庫
#service mysqld start
可通過檢查端口是否開啟來查看MySQL是否正常啟動:
[root@xxx]#netstat -anp|grep 3306
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 34693/mysqld
修改密碼等配置:
#######啟動mysql服務進程 [root@typecodes ~]# systemctl start mysqld #######配置mysql(設置密碼等) [root@typecodes ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y [設置root用戶密碼] New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! 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? [Y/n] 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? [Y/n] y [禁止root遠程登錄] ... Success! 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? [Y/n] y [刪除test數據庫] - Dropping test database... ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist ... Failed! Not critical, keep moving... - 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? [Y/n] y [刷新權限] ... Success! All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL! Cleaning up...
進入數據庫
# mysql #mysql -u root -p #輸入密碼
修改密碼:
>update mysql.user set authentication_string=password('root') where user='root'
設置遠程登陸:
mysql>use mysql; mysql> update user set host='%' where user='root'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '填寫root的密碼' WITH GRANT OPTION; mysql> FLUSH PRIVILEGES; mysql>SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; mysql>exit; #service mysqld restart
本地客戶端設置:
下載hedisql,新建一個會話
參考資料:
1. http://blog.csdn.net/qq_35750399/article/details/65479837
2.https://jingyan.baidu.com/album/93f9803f010d8fe0e56f555e.html?picindex=3
3.http://blog.csdn.net/yoon0205/article/details/50605584
4. https://www.jianshu.com/p/e723f3d68dc7
5.http://blog.csdn.net/lxpbs8851/article/details/10895085 忘記密碼怎么辦
6.https://stackoverflow.com/questions/16030453/redhat-mysql-failure 安裝server出錯的處理
7.https://typecodes.com/web/centos7yuminstallmysql5.html 初始密碼設置