这个是本人最早接触的一篇数据库配置,也是让我入门Linux基础环境搭建的一篇,有时候忘了命令也会参考里面的内容
# rpm -ivh 12-cmake-2.8.11.1-5.1.x86_64.rpm
warning: cmake-2.8.11.1-5.1.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 6aaf6b3f: NOKEY
Preparing... (10########################################### [100%]
1:cmake ( ########################################### [100%]
#tar -zxvf 13-mariadb-5.5.48-linux-glibc_214-x86_64.tar.gz
# mv mariadb-5.5.48-linux-x86_64 /usr/local/
# groupadd mysql
# useradd -g mysql mysql
# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
# ln -s mariadb-5.5.48-linux-x86_64/ mysql
# cd mysql/
#cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
# ./scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Installing MariaDB/MySQL system tables in ‘/var/lib/mysql‘ ...
160227 0:23:45 [Note] ./bin/mysqld (mysqld 5.5.48-MariaDB) starting as process 1105 ...OK
Filling help tables...
160227 0:23:47 [Note] ./bin/mysqld (mysqld 5.5.48-MariaDB) starting as process 1112 ...OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
#cp support-files/mysql.server /etc/init.d/
PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:
启动数据库:
#/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --user=mysql &
‘./bin/mysqladmin‘ -u root password ‘new-password‘
‘./bin/mysqladmin‘ -u root -h php.myfamily password ‘new-password‘
Alternatively you can run:
‘./bin/mysql_secure_installation‘
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.
You can start the MariaDB daemon with:
cd ‘.‘ ; ./bin/mysqld_safe --datadir=‘/var/lib/mysql‘
You can test the MariaDB daemon with mysql-test-run.pl
cd ‘./mysql-test‘ ; perl mysql-test-run.pl
Please report any problems at http://mariadb.org/jira
The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
Support MariaDB development by buying support/new features from MariaDB
Corporation Ab. You can contact us about this at [email protected]
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
# chown -R root .
# chown -R mysql data
# vi .bash_profile
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin/:/usr/local/apache2/bin/:/usr/local/php/bin/
:wq
启动数据库:
#/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --user=mysql &
设置开机自动启动数据库:
#vi /etc/rc.local
add
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --datadir=/usr/local/mysql/data --user=mysql &
:wq
#reboot
修改mysql root密码:
#‘./bin/mysqladmin‘ -u root password ‘new-password‘
or
# ./mysql_secure_installation
# ./bin/mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.48-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]> use mysql;
Database changed
MariaDB [mysql]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
MariaDB [mysql]> select host, user from user;
+--------------+------+
| host | user |
+--------------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| localhost | root |
| php.myfamily | |
| php.myfamily | root |
+--------------+------+
6 rows in set (0.00 sec)
MariaDB [mysql]> update user set host=‘%‘ where user=‘root‘ and host=‘localhost‘;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [mysql]> select host, user from user;
+--------------+------+
| host | user |
+--------------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| localhost | |
| php.myfamily | |
| php.myfamily | root |
+--------------+------+
6 rows in set (0.00 sec)
MariaDB [mysql]> delete from user where user=‘‘;
Query OK, 2 rows affected (0.03 sec)
修改数据库密码:
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’;
MariaDB [mysql]> select host, user, password from user;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| % | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |
| php.myfamily | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |
| 127.0.0.1 | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |
| ::1 | root | *0D2B78B43FD0518B55EFD87FC2C1FB6775F8AB07 |
+--------------+------+-------------------------------------------+
4 rows in set (0.00 sec)
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> exit
Bye
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
修改防火墙配置;
# vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
:wq
如果遇到下面的错误:
ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘
ps -ef | grep mysqld
查询确认mysql的pid,然后kill -9 xx
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD(’newpassword’) where USER=’root’;
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
mysql>